helpers.py
Go to the documentation of this file.
1 import config #/// User configuration
2 import log #/// Basic console logging
3 import json #/// read/write JSON
4 
5 from libs import requests #/// HTML CRUD operations
6 from libs import xmltodict #/// XML parsing
7 
8 
9 #///////////////////////////////////////////////////////////////////////////////
10 # Check blessed plots config
12  return json.loads(open(config.BLESSED_PLOTS).read())
13 
14 
15 #///////////////////////////////////////////////////////////////////////////////
16 # Make HTTP request to DocDB
17 def CallDocDB(function, parameter, value):
18  # Construct full url from parameter and value
19  url = config.DOCDB_URL + function + '?' + parameter + '=' + value + '&outformat=xml'
20 
21  # Make HTTP request
22  response = requests.get(url, auth=('nova', config.PWD))
23 
24  return xmltodict.parse(response.content)
25 
26 
27 #///////////////////////////////////////////////////////////////////////////////
28 # Get individual document from DocDB
29 def GetDoc(docID):
30  # Construct full url from parameter and value
31  url = config.DOCDB_URL + 'ShowDocument?docid=' + str(docID) + '&outformat=xml'
32 
33  # Make HTTP request
34  response = requests.get(url, auth=('nova', config.PWD))
35  return xmltodict.parse(response.content)
36 
37 
38 #///////////////////////////////////////////////////////////////////////////////
39 # Find all the topics to which a given plot belongs
40 def GetTopicsByDocID(docID):
41  topics = []
42  for topic in BlessedPlotsList():
43  if docID in topic['docs']:
44  topics.append(topic['category'])
45 
46  if len(topics) == 0:
47  topics = [unicode('uncategorized')]
48 
49  return topics
50 
51 
52 #///////////////////////////////////////////////////////////////////////////////
53 #
54 def CombineDocLists(_xml, _docIds):
55  for item in _xml:
56  docId = int(item['@id'])
57  if docId not in _docIds:
58  _docIds.append(docId)
59 
60  return 0
61 
62 
63 #///////////////////////////////////////////////////////////////////////////////
64 # Download a file
65 def Download(url, destination):
66  r = requests.get(url, auth=('nova', config.PWD))
67  with open(destination, "wb") as dest:
68  dest.write(r.content)
def CombineDocLists(_xml, _docIds)
Definition: helpers.py:54
def GetTopicsByDocID(docID)
Definition: helpers.py:40
def GetDoc(docID)
Definition: helpers.py:29
def CallDocDB(function, parameter, value)
Definition: helpers.py:17
def BlessedPlotsList()
Definition: helpers.py:11
procfile open("FD_BRL_v0.txt")
def Download(url, destination)
Definition: helpers.py:65