first commit
This commit is contained in:
commit
89221c78b6
5
README
Normal file
5
README
Normal file
|
@ -0,0 +1,5 @@
|
|||
create a file called settings.py like this:
|
||||
|
||||
username = 'yourusername'
|
||||
password = 'yourpassword'
|
||||
url = 'http://next.pad.ma/api'
|
0
__init__.py
Normal file
0
__init__.py
Normal file
157
utils.py
Normal file
157
utils.py
Normal file
|
@ -0,0 +1,157 @@
|
|||
from settings import username, password, url
|
||||
import ox
|
||||
import json
|
||||
import codecs
|
||||
|
||||
api = ox.api.API(url)
|
||||
user = api.signin({'username': username, 'password': password})
|
||||
|
||||
if user['data'].has_key("errors"):
|
||||
print "Authentication Failed!"
|
||||
|
||||
def titleContains(string):
|
||||
return api.find({
|
||||
'sort': [{
|
||||
'key': 'title',
|
||||
'operator': '+'
|
||||
}],
|
||||
'query': {
|
||||
'conditions': [
|
||||
{
|
||||
'key': 'title',
|
||||
'value': string,
|
||||
'operator': ''
|
||||
}
|
||||
],
|
||||
'operator': '&'
|
||||
},
|
||||
'keys': ['id', 'title']
|
||||
})
|
||||
|
||||
def getIdFromTitle(string):
|
||||
result = api.find({
|
||||
'sort': [{
|
||||
'key': 'title',
|
||||
'operator': '+'
|
||||
}],
|
||||
'query': {
|
||||
'conditions': [
|
||||
{
|
||||
'key': 'title',
|
||||
'value': string,
|
||||
'operator': '='
|
||||
}
|
||||
],
|
||||
'operator': '&'
|
||||
},
|
||||
'keys': ['id', 'title']
|
||||
})
|
||||
items = result['data']['items']
|
||||
if (len(items) > 1):
|
||||
raise Exception("more than 1 item matches title")
|
||||
elif (len(items) == 0):
|
||||
return None
|
||||
else:
|
||||
return items[0]['id']
|
||||
|
||||
def addFeaturedPerson(id, person):
|
||||
result = api.get({'id': id, 'keys': 'featured'})
|
||||
featured = result['data']['featured']
|
||||
if person in featured:
|
||||
return
|
||||
else:
|
||||
featured.append(person)
|
||||
return api.edit({
|
||||
'id': id,
|
||||
'featured': featured
|
||||
})
|
||||
|
||||
def dumpUnknownPlaces():
|
||||
result = api.findPlaces({
|
||||
"query": {
|
||||
"conditions": [{
|
||||
'key': 'lat',
|
||||
'value': None,
|
||||
'operator': '='
|
||||
}],
|
||||
"operator": ""
|
||||
},
|
||||
"keys": [
|
||||
"id",
|
||||
"countryCode",
|
||||
"type",
|
||||
"name",
|
||||
"alternativeNames",
|
||||
"lat",
|
||||
"lng",
|
||||
"area",
|
||||
"area",
|
||||
"geoname",
|
||||
"matches",
|
||||
"matches"
|
||||
],
|
||||
"range": [
|
||||
0,
|
||||
5000
|
||||
],
|
||||
"sort": [
|
||||
{
|
||||
"key": "geoname",
|
||||
"operator": "+"
|
||||
}
|
||||
]
|
||||
})
|
||||
out = codecs.open("unknownplaces.json", "w", encoding="utf-8")
|
||||
json.dump(result['data']['items'], out)
|
||||
out.close()
|
||||
return result
|
||||
|
||||
|
||||
def dumpKnownPlaces():
|
||||
result = api.findPlaces({
|
||||
"query": {
|
||||
"conditions": [{
|
||||
'key': 'lat',
|
||||
'value': None,
|
||||
'operator': '!'
|
||||
}],
|
||||
"operator": ""
|
||||
},
|
||||
"keys": [
|
||||
"id",
|
||||
"countryCode",
|
||||
"type",
|
||||
"name",
|
||||
"alternativeNames",
|
||||
"lat",
|
||||
"lng",
|
||||
"area",
|
||||
"area",
|
||||
"geoname",
|
||||
"matches",
|
||||
"matches"
|
||||
],
|
||||
"range": [
|
||||
0,
|
||||
5000
|
||||
],
|
||||
"sort": [
|
||||
{
|
||||
"key": "geoname",
|
||||
"operator": "+"
|
||||
}
|
||||
]
|
||||
})
|
||||
out = codecs.open("knownplaces.json", "w", encoding="utf-8")
|
||||
json.dump(result['data']['items'], out)
|
||||
out.close()
|
||||
return result
|
||||
|
||||
|
||||
#def replaceAnnotation(track, old, new):
|
||||
|
||||
|
||||
|
||||
|
||||
def getIds(result):
|
||||
return [item.id for item in result['data']['items']]
|
Loading…
Reference in New Issue
Block a user