You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
717 B
34 lines
717 B
#!/usr/bin/env python3
|
|
|
|
import requests, datetime, os
|
|
import sqlite3, time
|
|
|
|
now = datetime.datetime.now()
|
|
day = now.strftime('%F')
|
|
the_time = now.strftime('%H:%M')
|
|
|
|
url = 'https://solar.lowtechmagazine.com/api/stats.json'
|
|
|
|
if not os.path.exists('stats.db'):
|
|
db = sqlite3.connect('stats.db')
|
|
c = db.cursor()
|
|
c.execute("""CREATE TABLE stats(date text, time text, error text, server text)
|
|
""")
|
|
else:
|
|
db = sqlite3.connect('stats.db')
|
|
c = db.cursor()
|
|
|
|
r = requests.get(url)
|
|
|
|
if not r.status_code == 200:
|
|
error = r.status_code
|
|
data = None
|
|
else:
|
|
error = None
|
|
data = r.text
|
|
|
|
c.execute("""INSERT INTO stats VALUES(?,?,?,?)""", (day, the_time, error, data))
|
|
|
|
db.commit()
|
|
db.close()
|
|
|
|
|