-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettoknow.py
executable file
·37 lines (30 loc) · 915 Bytes
/
gettoknow.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
from flask import Flask, render_template
import json
import feedparser
import globalvoices
from pymongo import MongoClient
import logging
app = Flask(__name__)
c = MongoClient('localhost',27017)
mongo_stories = c.gv.stories
@app.route("/")
def index():
return render_template("stories.html",
country_list_json_text=json.dumps(globalvoices.country_list())
)
@app.route("/country/<country>")
def country(country):
if mongo_stories.find({'country':country}).count > 0:
stories = mongo_stories.find({'country':country})
else:
stories = globalvoices.recent_stories_from( country )
for story in stories:
mongo_stories.insert(story)
return render_template("stories.html",
country_list_json_text=json.dumps(globalvoices.country_list()),
country_name=country,
stories=stories
)
if __name__ == "__main__":
app.debug = True
app.run()