forked from data-for-change/anyway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_discussions.py
executable file
·39 lines (34 loc) · 1.13 KB
/
load_discussions.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
# -*- coding: utf-8 -*-
import argparse
from models import DiscussionMarker
import re
from database import db_session
import sys
import logging
def main():
parser = argparse.ArgumentParser()
parser.add_argument('identifiers', type=str, nargs='*',
help='Disqus identifiers to create markers for')
args = parser.parse_args()
identifiers = args.identifiers if args.identifiers else sys.stdin
for identifier in identifiers:
m = re.match('\((\d+\.\d+),\s*(\d+\.\d+)\)', identifier)
if not m:
logging.error("Failed processing: " + identifier)
continue
(latitude, longitude) = m.group(1, 2)
marker = DiscussionMarker.parse({
'latitude': latitude,
'longitude': longitude,
'title': identifier,
'identifier': identifier
})
try:
db_session.add(marker)
db_session.commit()
logging.info("Added: " + identifier, end="")
except:
db_session.rollback()
logging.warn("Failed: " + identifier, end="")
if __name__ == "__main__":
main()