This program log on to a website, and get som information.
The import block:
1 2 3 4 5 6 | #!/usr/bin/python
import time
from time import gmtime, strftime
import socket
import Adafruit_CharLCD as LCD
import requests
|
Assignment:
time_counter = 0
lcd_rs = 25
lcd_en = 24
lcd_d4 = 23
lcd_d5 = 17
lcd_d6 = 18
lcd_d7 = 22
lcd_bac = 4
lcd_col = 16
lcd_row = 2
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_col, lcd_row, lcd_bac)
headers = {
'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
login_data = {
'name': 'xxxx',
'pass': 'xxxxx'
}
url = "http://xxxxx"
count_url = "http://xxxx"
current_shot = "0"
This lines of code, get the IP of the host the program is running on.
my_ip = ([l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)),
s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)]][0][1]]) if l][0][0])
lcd.message("IP:\n" + my_ip)
time.sleep(5)
lcd.clear()
while True:
current_time = strftime("%H:%M:%S")
lcd.message("Time : " + current_time + "\n")
lcd.message("Shots: " + current_shot)
time.sleep(1)
lcd.set_cursor(0,0)
time_counter += 1
if time_counter > 5:
time_counter = 0
with requests.Session() as s:
r = s.get(url, headers=headers)
r = s.post(url, data=login_data, headers=headers)
r = s.get(count_url, headers=headers)
current_shot = (r.content)
lcd.clear()
# lcd.message(current_shot)
print current_shot