dtaabase caller connected and bugfix

This commit is contained in:
Your Name 2022-01-24 18:40:06 +00:00
parent a25c82128c
commit 5d7ec03d41
5 changed files with 42 additions and 15 deletions

View File

@ -133,7 +133,7 @@ def updateCrypto():
response = requests.get(url) response = requests.get(url)
data = response.json() data = response.json()
print(data) print(data)
sys.exit()
stock_info = {} stock_info = {}
@ -270,18 +270,23 @@ def updateNews():
response = requests.get(url) response = requests.get(url)
data = response.json() data = response.json()
#load user settings #load user settings
headlines = data headlines = data
headline_sources = [headline['source'] for headline in headlines]
except Exception as e: except Exception as e:
print('news ettings not used', e) print('news ettings not used', e)
#if no settings just get top headlines #if no settings just get top headlines
headlines = newsapi.get_top_headlines() headlines = newsapi.get_top_headlines()['articles']
headline_sources = [headline['source']['name'] for headline in headlines]
headline_titles = [headline['title'] for headline in headlines['articles']] headline_titles = [headline['title'] for headline in headlines]
headline_sources = [headline['source']['name'] for headline in headlines['articles']]
headline_times = [headline['publishedAt']for headline in headlines['articles']] headline_times = [headline['publishedAt'] for headline in headlines]
headlines = list(zip(headline_titles, headline_sources, headline_times)) headlines = list(zip(headline_titles, headline_sources, headline_times))
print(headlines)
all_settings['headlines'] = headlines all_settings['headlines'] = headlines
json.dump(all_settings, open('csv/news_settings.json', 'w+')) json.dump(all_settings, open('csv/news_settings.json', 'w+'))
@ -289,6 +294,7 @@ def updateNews():
except Exception as e: except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info() exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
logf.write(str(e)) logf.write(str(e))

View File

@ -16,16 +16,19 @@ import pexpect
import time import time
import json import json
from multiprocessing import Process from multiprocessing import Process
import subprocess
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import numpy as np import numpy as np
import copy import copy
import urllib.request
#stock_ticker = StockTicker() #stock_ticker = StockTicker()
#print('API CALLER NOT STARTED') #print('API CALLER NOT STARTED')
#open('log.txt', 'w').close() #wipe logs #open('log.txt', 'w').close() #wipe logs
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py") #api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 api_caller.py")
api_caller = pexpect.spawn("sudo -E taskset -c 3 python3 database_caller.py")
api_caller.sendline('A') api_caller.sendline('A')
displaying_screensaver = False displaying_screensaver = False
uploading = False uploading = False
@ -337,7 +340,7 @@ def edit_wpa_sup(country, ssid, pwd):
@app.route("/wifi", methods = ['PUT', 'POST', 'GET']) @app.route("/wifi", methods = ['PUT', 'POST', 'GET'])
def wifi(): def set_wifi():
data= request.data.decode('utf-8') data= request.data.decode('utf-8')
print(str(data)) print(str(data))
@ -357,6 +360,24 @@ def wifi():
os.system('wpa_cli -i wlan0 reconfigure') os.system('wpa_cli -i wlan0 reconfigure')
return index() return index()
def check_internet_connection(host='http://google.com'):
try:
urllib.request.urlopen(host) #Python 3.x
return True
except:
return False
def check_network_connection():
ps = subprocess.Popen(['iwconfig'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try:
output = subprocess.check_output(('grep', 'ESSID'), stdin=ps.stdout)
return True
except subprocess.CalledProcessError:
# grep did not match any lines
print("No wireless networks connected")
return False
def edit_hosts(hostname): def edit_hosts(hostname):
current_hosts = open('/etc/hosts') current_hosts = open('/etc/hosts')
@ -510,6 +531,8 @@ def save_news_settings(input_settings):
current_settings = json.load(open('csv/' + filename, 'r')) current_settings = json.load(open('csv/' + filename, 'r'))
print(current_settings)
current_settings['speed'] = input_settings['speed'].lower() current_settings['speed'] = input_settings['speed'].lower()
current_settings['animation'] = input_settings['animation'].lower() current_settings['animation'] = input_settings['animation'].lower()
current_settings['title'] = input_settings['title'] current_settings['title'] = input_settings['title']
@ -518,6 +541,7 @@ def save_news_settings(input_settings):
current_settings['sources'] = list(set(current_settings['sources'] + input_settings['sources'])) current_settings['sources'] = list(set(current_settings['sources'] + input_settings['sources']))
print(current_settings)
json.dump(current_settings, open('csv/' + filename, 'w+')) json.dump(current_settings, open('csv/' + filename, 'w+'))
api_caller.sendline('n') api_caller.sendline('n')

View File

@ -962,10 +962,7 @@ function getFeatureSettings() {
case 5: case 5:
s = getWeatherSettings(page); s = getWeatherSettings(page);
break; break;
case 6:fetch("/upload", { case 6:
method: "POST",
body: data,
});
s = getNewsSettings(page); s = getNewsSettings(page);
break; break;
case 7: case 7:

View File

@ -1089,7 +1089,7 @@ class StockTicker():
current = '%.3f' % current current = '%.3f' % current
midFrame = self.textToImage(symbol+ '(' + base + ')', current, arrow, percent_change, point_change) #IMAGE THE TEXT midFrame = self.textToImage(base+ '(' + symbol + ')', current, arrow, percent_change, point_change) #IMAGE THE TEXT
if all_forex_settings['logos']: if all_forex_settings['logos']:

View File

@ -1520,9 +1520,9 @@
id="inputScrollSpeed62" id="inputScrollSpeed62"
class="form-select country-select" class="form-select country-select"
> >
<option>USA</option> <option>US</option>
<option>UK</option> <option>GB</option>
<option>China</option>
</select> </select>
</div> </div>
</div> </div>