forked from brunobord/neigefr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.py
36 lines (33 loc) · 987 Bytes
/
flake.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
import json
from neigefr.helpers import find_zipcode, parse_body
from neigefr.models import Snowflake, Zipcode
from neigefr.geo import get_geo
def process(data):
"Process JSON data"
flake = parse_body(data['text'])
if not flake:
return None
if not flake.zipcode:
return None
zipcode = find_zipcode(flake.zipcode)
if not zipcode:
longitude, latitude, city = get_geo(flake.zipcode)
if city:
zipcode = Zipcode.objects.create(
zipcode=flake.zipcode,
city=city,
longitude=longitude,
latitude=latitude
)
else:
print "Zipcode pas trouve", flake.zipcode
return
snowflake = Snowflake.objects.create(
tweet_id=data['id'],
tweet=json.dumps(data),
latitude=zipcode.latitude,
longitude=zipcode.longitude,
rank=flake.ranking,
zipcode=zipcode,
)
return snowflake