-
Notifications
You must be signed in to change notification settings - Fork 1
/
will's test code.txt
75 lines (61 loc) · 1.98 KB
/
will's test code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#import serial
import json
#import requests
import socket
from ftplib import FTP
from pprint import pprint
#import pyowm
import urllib.request
from html.parser import HTMLParser
from html.entities import name2codepoint
dataList = []
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Start tag:", tag)
for attr in attrs:
print(" attr:", attr)
def handle_endtag(self, tag):
print("End tag :", tag)
def handle_data(self, data):
print("Data :", data)
dataList.append(data)
def handle_comment(self, data):
print("Comment :", data)
def handle_entityref(self, name):
c = chr(name2codepoint[name])
print("Named ent:", c)
def handle_charref(self, name):
if name.startswith('x'):
c = chr(int(name[1:], 16))
else:
c = chr(int(name))
print("Num ent :", c)
def handle_decl(self, data):
print("Decl :", data)
class ArduinoPortal:
#req = requests.get('http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=d2669a720677f99ab5ac96c0dca9a399')
#apiData = json.loads(req)
#pprint(req.json())
#ser = serial.Serial('COM5', 9600, timeout=10)
#print(ser.name)
#arduinoData = ser.readLine()
#ser.close()
#ftp = FTP('smart-irrigation.site')
#try:
#print('Logging In...')
#ftp.login('arduino@smart-irrigation.site', 'jD3isqixviHr')
#except:
# print('Failed to login')
#ftp.retrlines('LIST')
#file = open('text.json', 'rb')
#ftp.storbinary('STOR text.json', file)
#ftp.retrlines('LIST')
#ftp.quit()
contents = urllib.request.urlopen("http://172.20.10.3").read()
print("Pre Parser: ",contents)
f= open("temp.txt","w+")
f.write(str(contents))
parser = MyHTMLParser()
parser.feed(str(contents))
print(str(dataList))
print(dataList[3])