blob: 456ff8537c1fdcfa589b7223bec2889c9482938f (
plain)
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
|
import os
import sys
import simplejson as json
from ricky.config import OFFLINE, PB_DATA_URL
import ricky.utils as utils
class Pb(object):
def __init__(self):
self.url = ""
self._offline = OFFLINE
def call(self, params):
if self._offline:
sys.path.append("./photoblaster")
from photoblaster.modules import Pb as _Pb
from photoblaster.config import LOCAL as PBLOCAL
for pbcls in _Pb.__subclasses__():
if pbcls.__name__ == self.__class__.__name__:
params_dict = params.as_dict()
instance = pbcls(**params_dict)
instance.create()
if not PBLOCAL:
instance.file_s3move()
return instance.file_dict()
return json.loads(
utils.http_request(self.url, params=params.as_dict())
)
def data_from_url(self, url):
"""
retrieves image params from db using the url
"""
newfile = os.path.split(url)[-1]
if self._offline:
sys.path.append("./photoblaster")
from photoblaster.db.models.imcmd import ImCmd
result = ImCmd.search(newfile=newfile).first()
try:
return {
"module": result.tag.split(":")[0],
"params": json.loads(result.dataobj)
}
except AttributeError:
sys.stderr.write("No usable data found in db\n")
return None
else:
print utils.http_request("%s?newfile=%s" % (PB_DATA_URL, newfile))
raise NotImplementedError("Not yet implemented\n")
|