From 2bd04bc36f7d2ca6889cc56c6aa3414da76f34fc Mon Sep 17 00:00:00 2001 From: ymkymkymkymx <43044797+ymkymkymkymx@users.noreply.github.com> Date: Fri, 13 Nov 2020 13:45:39 -0500 Subject: [PATCH] set up environment --- __pycache__/weather.cpython-37.pyc | Bin 0 -> 657 bytes taskrunner.py | 23 +++++++++++++++++------ weather.py | 18 ++++-------------- 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 __pycache__/weather.cpython-37.pyc diff --git a/__pycache__/weather.cpython-37.pyc b/__pycache__/weather.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5c7b81a302155d1cbe958ea5d41b14eb7aa62084 GIT binary patch literal 657 zcmYjP&2G~`5Z+y{V>h7)3PSJ#NRdhc5nQU4-v%LpdT5FYt4NXYZW6b#*NoSMH1P=@ zBoQYryi2cp<-{v+Vm1VcvF7u5cE9mAJNtZlyH3!)UH%wcQbK;ZkAKE6c#2*;M36+% z2@&qiCNyP&rJnFoE_mt-pZ;C1iJJ5z|4Kw4X^%AhU&tg!O>X^{lc+ei0jQ6qDvS-z z3Y{gxnGHe71XOHd{QcT|#1Q=jdU1?k$QhON4yovD*D%R2BGRjv@s?cjrN1BxwxBC- zMJsRNEo&=M@l%rB;=}~!b$COGdrbI+^vFB1;7-_)rLhezl04Q@3HG*kaX2<6-)py{ zJZb4%Wm6TIv4S+pTN*}f8JVcvX+3Ih@=uU^Fuz~z&L32FqdZUK!Msy7w=C0z4OI3i z0iB5eOUNWPuFZAhh4n_t*xFEIWh1yd2D{b$9IMYl+7K$&F< z`WtR5pV=EIXb_hGDl>ykp1ZT(K_IkF84W3?H|Z666(exzW(e-y2!H6t3ht(W=fDxc iO%U7&*L&B>{)6kdV8i`X%W|R~yQvp7gpl6G>VE(nCajMD literal 0 HcmV?d00001 diff --git a/taskrunner.py b/taskrunner.py index 0400153..b954dfe 100644 --- a/taskrunner.py +++ b/taskrunner.py @@ -1,16 +1,27 @@ from apscheduler.schedulers.blocking import BlockingScheduler -import time sched = BlockingScheduler() from weather import * - +import os @sched.scheduled_job('interval', hours=3) -def timed_job1(): - thedict=get_current_weather() - print('This job is run every three hours.') +def weatehrupdate(): + try: + connection = psycopg2.connect(user = os.environ["DB_USER"], + password = os.environ["DB_PASS"], + host = os.environ["DB_HOST"], + port = os.environ["DB_PORT"], + database = os.environ["DB_NAME"] ) -@sched.scheduled_job('interval', hours=3) + cursor = connection.cursor() + connection.autocommit = True + except (Exception, psycopg2.Error) as error : + print ("Error while connecting to PostgreSQL", error) + finally: + if(connection): + cursor.close() + connection.close() +@sched.scheduled_job('interval', hours=16) def timed_job2(): print('This is the number in number.txt: {0}') diff --git a/weather.py b/weather.py index cbcdba3..4e1b91d 100644 --- a/weather.py +++ b/weather.py @@ -1,24 +1,14 @@ import requests from flask import Flask, request, jsonify, redirect - -def get_current_weather_json(): - CLIENT_IP = request.remote_addr - GEO_KEY = "Api Key Goes Here" - WEATHER_KEY = 'Api Key Goes Here' - CURRENT_GEO_ENDPOINT = 'https://api.ipgeolocation.io/ipgeo?apiKey={0}&ip={1}&fields=geo'.format(GEO_KEY,CLIENT_IP) - r = requests.get(CURRENT_GEO_ENDPOINT) - thedict=r.json() +import os +def get_current_weather(zipcode): + WEATHER_KEY = os.environ["c"] try: zipcode=thedict['zipcode'] - countrycode=thedict['country_code2'] + countrycode="US" wr = requests.get('http://api.openweathermap.org/data/2.5/weather?zip={0},{1}&appid={2}'.format(zipcode,countrycode,WEATHER_KEY)) weatherdict=wr.json() except Exception: return dict() return weatherdict -def get_current_weather(): - if bool(get_current_weather_json()): - if get_current_weather_json()['cod'] == 200: - return get_current_weather_json()['weather'][0] - return dict() \ No newline at end of file