Skip to content

Commit

Permalink
set up environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkymkymkymx committed Nov 13, 2020
1 parent 7decf5b commit 2bd04bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Binary file added __pycache__/weather.cpython-37.pyc
Binary file not shown.
23 changes: 17 additions & 6 deletions taskrunner.py
Original file line number Diff line number Diff line change
@@ -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}')
Expand Down
18 changes: 4 additions & 14 deletions weather.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2bd04bc

Please sign in to comment.