-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
executable file
·68 lines (49 loc) · 2.16 KB
/
helpers.py
File metadata and controls
executable file
·68 lines (49 loc) · 2.16 KB
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
import config #/// User configuration
import log #/// Basic console logging
import json #/// read/write JSON
from libs import requests #/// HTML CRUD operations
from libs import xmltodict #/// XML parsing
#///////////////////////////////////////////////////////////////////////////////
# Check blessed plots config
def BlessedPlotsList():
return json.loads(open(config.BLESSED_PLOTS).read())
#///////////////////////////////////////////////////////////////////////////////
# Make HTTP request to DocDB
def CallDocDB(function, parameter, value):
# Construct full url from parameter and value
url = config.DOCDB_URL + function + '?' + parameter + '=' + value + '&outformat=xml'
# Make HTTP request
response = requests.get(url, auth=('uboone', config.PWD))
return xmltodict.parse(response.content)
#///////////////////////////////////////////////////////////////////////////////
# Get individual document from DocDB
def GetDoc(docID):
# Construct full url from parameter and value
url = config.DOCDB_URL + 'ShowDocument?docid=' + str(docID) + '&outformat=xml'
# Make HTTP request
response = requests.get(url, auth=('uboone', config.PWD))
return xmltodict.parse(response.content)
#///////////////////////////////////////////////////////////////////////////////
# Find all the topics to which a given plot belongs
def GetTopicsByDocID(docID):
topics = []
for topic in BlessedPlotsList():
if docID in topic['docs']:
topics.append(topic['category'])
if len(topics) == 0:
topics = [unicode('uncategorized')]
return topics
#///////////////////////////////////////////////////////////////////////////////
#
def CombineDocLists(_xml, _docIds):
for item in _xml:
docId = int(item['@id'])
if docId not in _docIds:
_docIds.append(docId)
return 0
#///////////////////////////////////////////////////////////////////////////////
# Download a file
def Download(url, destination):
r = requests.get(url, auth=('uboone', config.PWD))
with open(destination, "wb") as dest:
dest.write(r.content)