HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: codedmind on October 05, 2014, 11:15:38 AM
-
How to do if we want import python library into python script?
Can that be done?
I have the following code in python script and try put it in hg program.
Thanks
import glob
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('[url]http://192.168.1.64/listdev.htm'[/url] ([url]http://192.168.1.64/listdev.htm'[/url])).read())
#data = soup('table')[2].tbody('td',{'class':'valid'})[1].get_text()
dataPower = soup('table')[2].tbody('td')[10].get_text()
lastScan = soup('table')[2].tbody('td')[16].get_text()
-
It can be done by adding the library directory to the lib search path:
import sys
sys.path.append("/usr/lib/python2.7/")
for more info about the Python engine used in HG see:
http://ironpython.net/documentation/ (http://ironpython.net/documentation/)
Cheers,
g.
-
Hy Gene
With the following code
"""
Python Automation Script
Example for using Helper Classes:
hg.Modules.WithName('Light 1').On()
"""
import sys
sys.path.append("/usr/lib/python2.7/")
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen('http://192.168.1.64/listdev.htm').read())
#data = soup('table')[2].tbody('td',{'class':'valid'})[1].get_text()
dataPower = soup('table')[2].tbody('td')[10].get_text()
lastScan = soup('table')[2].tbody('td')[16].get_text()
hg.Program.Notify("HelloPY",dataPower)
I get this error
Line 0, Column 0 (Program Code):
An exception was thrown by the type initializer for CodecsInfo
-
Some dependency missing? Can't help much on python =/
Btw, you can use hg NetHelper class to achieve the same result:
data = hg.Net.WebService("http://192.168.1.64/listdev.htm").GetData()
if fetched data is XML or JSON then the returned value (data) is the resulting deserialized object.
Otherwise it is a string that you have to parse in some other way (and that is the case).
g.
-
The problem is that, and i don't now why i can't compile c# programs
And to parse the html output i need the BeautifulSoup import and can't put it to work :/
-
Hi codemind,
by googling I found this:
https://bugs.launchpad.net/ubuntu/+source/dlr-languages/+bug/598411
Eric Talevich (eric-talevich) wrote on 2010-07-03: #1
I fixed this by installing the mono library: libmono-i18n2.0-cil
Looks like that package should be added as a dependency of the ironpython package.
so try an sudo apt-get install libmono-system-componentmodel-dataannotations4.0-cil libmono-i18n2.0-cil .
Hope this helps!
Cheers,
g.
-
hy Gene
Thanks, but still not working :/
"""
Python Automation Script
Example for using Helper Classes:
hg.Modules.WithName('Light 1').On()
"""
import sys
sys.path.append("/usr/lib/python2.7/")
import urllib2
from bs4 import BeautifulSoup
hg.Program.Notify("HelloPY","buuu")
the error
Line 0, Column 0 (Program Code):
An exception was thrown by the type initializer for CodecsInfo
-
Since this seems to be a mono bug, we can just wait.
Isn't there any BeautifulSoup alternative for parsing?
g.