Skip to content

Commit

Permalink
Try to use the weather.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkymkymkymx committed Nov 9, 2020
1 parent 6119efb commit 7decf5b
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 138 deletions.
1 change: 0 additions & 1 deletion number.txt

This file was deleted.

1 change: 0 additions & 1 deletion number1.txt

This file was deleted.

15 changes: 0 additions & 15 deletions scanandshow.py

This file was deleted.

19 changes: 6 additions & 13 deletions taskrunner.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
from apscheduler.schedulers.blocking import BlockingScheduler
import time
sched = BlockingScheduler()
from weather import *




@sched.scheduled_job('interval', seconds=3)
@sched.scheduled_job('interval', hours=3)
def timed_job1():
f=open("number.txt","w")
num=time.clock()
num=str(num)
f.write(num)
f.close()
print('This job is run every three seconds.')
thedict=get_current_weather()
print('This job is run every three hours.')

@sched.scheduled_job('interval', seconds=3)
@sched.scheduled_job('interval', hours=3)
def timed_job2():
f=open("number.txt","r")

num=f.readline()
f.close()
print('This is the number in number.txt: {0}'.format(num))
print('This is the number in number.txt: {0}')

sched.start()
18 changes: 0 additions & 18 deletions templates/index.html

This file was deleted.

18 changes: 0 additions & 18 deletions templates/index.txt

This file was deleted.

18 changes: 0 additions & 18 deletions templates/time.html

This file was deleted.

18 changes: 0 additions & 18 deletions templates/time.txt

This file was deleted.

18 changes: 0 additions & 18 deletions templates/weather.html

This file was deleted.

18 changes: 0 additions & 18 deletions templates/weather.txt

This file was deleted.

24 changes: 24 additions & 0 deletions weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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()
try:
zipcode=thedict['zipcode']
countrycode=thedict['country_code2']
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 7decf5b

Please sign in to comment.