Author Topic: DigRGBMail.py syntax error on line 25  (Read 12428 times)

bhodgs01

  • Newbie
  • *
  • Posts: 15
DigRGBMail.py syntax error on line 25
« on: February 05, 2013, 09:46:46 pm »
I am having a little trouble getting the DigiRGBMail.py program working.  I am getting a syntax error on line 25.   any idea why?  Also, I am supposed to add my mailinator email after the email= right? 


I would really like to get this working with IFTTT.


Thanks... code below...




import sys
import time
import urllib2
import re
import os
import webcolors
rss_url = "http://www.mailinator.com/rss.jsp?email=" + sys.argv[1]
current = ['0','0','0']


while 1:
   feed = urllib2.urlopen(rss_url).read()
   matches = re.findall('<title>([^>]*)<\/title>', feed)
   if len(matches)>1:
      newest_subject = matches[len(matches)-1].strip()
      newest_subject = newest_subject.split(" ",3)
      if len(newest_subject) != 3:
         newest_subject = matches[len(matches)-1].strip()
         try:
            newest_subject = webcolors.name_to_rgb(newest_subject.lower())
            newest_subject = list(newest_subject)
         except ValueError:
            newest_subject = current


      if current != newest_subject:
         print newest_subject       <---------syntax error here*******
         os.system('DigiRGB ' + str(newest_subject[0]) + ' ' + str(newest_subject[1]) + ' ' + str(newest_subject[2]))


      current = newest_subject
   time.sleep(60)

bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #1 on: February 06, 2013, 04:53:20 pm »
Well... I found the answer to one question and now I have many more.  it appears this was written in python 2 and I am using python 3.3.  the syntax error is caused by not adding parenthesis print (newest_subject)


I think this program will take a lot of rewriting to get to work so I am going to try to downgrade my python


If anyone has figured this out in python 3.3, please let me know!

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #2 on: February 06, 2013, 04:56:27 pm »
It was written for 2.7 - which explains why I kept coming back to your question today and wasn't able to ever replicate the issue.


What OS are you on?




bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #3 on: February 06, 2013, 04:59:25 pm »
Windows 7.  I am going to try to install the 2.7 python. 


bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #4 on: February 06, 2013, 05:01:38 pm »
Thanks for all your help.  I was the one who asked you about the blink(1) last week.  I have been trying to get this to work since then.   this should satisfy what I was looking to do.   You don't know what is needed to get this code running in python 3.3 do you?  so far I have found some differences in the urllib and re libraries


bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #5 on: February 06, 2013, 06:31:22 pm »
so I think I am getting closer.  I downgraded to 2.73 and ran the program python C:\python273\scripts\RGBmail.py myemail@mailinator.com . I don't get any errors but  it just hangs there.  I sent an email with the subject of 255 0 0 to myemail@mailinator.com and still nothing..... am I missing a step or doing something wrong?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #6 on: February 06, 2013, 07:40:28 pm »
Leave off the "@mailinator.com" when you start the program - right now your checking myemail@mailinator.com@mailinator.com - obviously the readme should state that as well - but that should do it.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #7 on: February 06, 2013, 07:42:09 pm »
Oh I just realized that this assumes DigiRGB is an executable in the same directory, so if it is .py script instead (in the same directory) you might want to change




os.system('DigiRGB ' + str(newest_subject[0]) + ' ' + str(newest_subject[1]) + ' ' + str(newest_subject[2]))

to

os.system('python DigiRGB.py ' + str(newest_subject[0]) + ' ' + str(newest_subject[1]) + ' ' + str(newest_subject[2]))
« Last Edit: February 06, 2013, 08:38:57 pm by digistump »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #8 on: February 06, 2013, 08:38:39 pm »
You'll also need to move the arduino folder that is in with the python examples into your code directory.


bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #9 on: February 07, 2013, 09:08:00 am »
still have a bit of trouble but slowly progressing.  I put the DigiRGB.py in the same folder as DigiRGBmail and I keep getting Erno [2] no such file or directory


When I try to run the DigiRGB by itself, I get the attached error.

 
any suggestions?

bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #10 on: February 07, 2013, 09:33:32 am »
I get the same error when I do run DigiRGB 255 0 0


digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #11 on: February 07, 2013, 01:32:57 pm »
this has to do with pyusb - I'm not sure the root of the error


Since your on windows have you tried the precompiled DigiRGMMail.exe file? just run it from the console with the email after it, just like the script

bhodgs01

  • Newbie
  • *
  • Posts: 15
Re: DigRGBMail.py syntax error on line 25
« Reply #12 on: February 07, 2013, 05:40:54 pm »
I downloaded a new pyusb and that fixed one thing but now I am getting different errors :'( I couldn't get the exe to work either.




digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #13 on: February 07, 2013, 05:59:07 pm »
try entering the directory first:


cd C:\Python27


python DigiRGBMail.py emailaddress

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: DigRGBMail.py syntax error on line 25
« Reply #14 on: February 07, 2013, 05:59:34 pm »
and what do you get when run the exe?