-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6119efb
commit 7decf5b
Showing
11 changed files
with
30 additions
and
138 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |