-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWeather.py
92 lines (73 loc) · 2.58 KB
/
Weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from flask import Flask, jsonify
from flask import render_template,request
import os
import requests
from rivescript import RiveScript
bot = RiveScript()
bot.load_directory(
os.path.join(os.path.dirname(__file__), "brain")
)
bot.sort_replies()
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/codepen')
def codepen():
return render_template('codepen.html')
@app.route('/temperature',methods=['POST'])
def temperature():
cityName=request.form['cityName']
getRequests=requests.get('http://api.openweathermap.org/data/2.5/weather?q='+cityName+',uk&appid=59026d61966be7eab971e0e48eb22bbc')
print(getRequests.text)
#print(cityName)
jsonObject=getRequests.text
#return jsonObject
json_Parser=getRequests.json()
temperature_only=json_Parser['main']['temp']
#temp_data={"inputValue":request.args.get('temperature')}
#print(json_Parser)
return jsonify({'data':temperature_only})
@app.route('/v1',methods=['POST'])
def shortAnswers():
question=request.form['question']
WOLF_URL = "http://api.wolframalpha.com/v1/"
# SHORT_ANS_URL = WOLF_URL + "result?i=question%3F&appid={}".format(wolfram_api_key)
SHORT_ANS_URL = WOLF_URL + "result?i="+question+"&appid=5V6EGT-9UTQ4G7P5Q"
response = requests.get(SHORT_ANS_URL)
i = response.text
j = "Wolfram|Alpha did not understand your input"
if (i != j):
answer = response.text
return jsonify({'data': answer})
@app.route("/rive", methods=["GET", "POST"])
def hello_rivescript():
"""Receive an inbound SMS and send a reply from RiveScript."""
from_number = request.values.get("From", "unknown")
message = request.values.get("Body")
reply = "(Internal error)"
# Get a reply from RiveScript.
if message:
reply = bot.reply(from_number, message)
# Send the response.
# resp = twilio.twiml.Response()
# resp.message(reply)
return str(reply)
@app.route('/articles',methods=['GET'])
def news():
msg=''
getRequests = requests.get("https://newsapi.org/v1/articles?source=the-times-of-india&sortBy=latest&apiKey=90b5a2960a63444da339b3cd7a1327d9")
#print(cityName)
jsonObject=getRequests.text
#return jsonObject
ans = getRequests.json()
result = ans['articles']
for i in range(5):
msg = msg + (result[i]['description'])
msg = msg + '\n' + '\n' + '\n'
#print(json_Parser)
return jsonify({'data':msg})
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.debug = True
app.run(host='0.0.0.0', port=port)