Commit 6f483e8ea405f4c3047554ee369910dcd07e1c29

Authored by pikidev ago
Exists in master

Merge branch 'master' of http://gitlab.pikicast.com/Noah/dsfacebook

Showing 4 changed files Side-by-side Diff

insight/pageinsight.py View file @ 6f483e8
... ... @@ -10,6 +10,13 @@
10 10 token = ""
11 11 data = {}
12 12 page_insight = {}
  13 + page_dscp = {'page_fans/lifetime': 'Lifetime_Total_Likes',
  14 + 'page_impressions_unique/day': 'Daily_Total_Reach',
  15 + 'page_engaged_users/day': 'Daily_Page_Engaged_Users',
  16 + 'page_storytellers_by_story_type/day': 'Daily_Talking_About_This_By_Story_Type',
  17 + 'page_impressions_unique/week': 'Weekly_Total_Reach',
  18 + 'page_engaged_users/week': 'Weekly_Page_Engaged_Users',
  19 + 'page_storytellers_by_story_type/week': 'Weekly_Talking_About_This_By_Story_Type'}
13 20  
14 21 def __init__(self, token):
15 22 self.token = token.getToken()
... ... @@ -22,11 +29,15 @@
22 29 % (page_id, i, int(time.time()), int(time.time()) + 12 * 60 * 60, self.token)
23 30 txt = requests.get(url).text
24 31 self.data = json.loads(txt)
25   - name = str(self.data['data'][0]['title'])
26   - val = self.data['data'][0]['values'][0]['value']
27   - if type(val) == type({}):
28   - val = sum(val.values())
29   - self.page_insight[name] = str(val)
  32 +
  33 + try:
  34 + name = str(self.data['data'][0]['title'])
  35 + val = self.data['data'][0]['values'][0]['value']
  36 + if type(val) == type({}):
  37 + val = sum(val.values())
  38 + self.page_insight[name] = str(val)
  39 + except:
  40 + self.page_insight[self.page_dscp[i].replace("_", " ")] = 0
30 41 return self.page_insight
31 42  
32 43 def getPageInsightByKey(self, key):
insight/url.py View file @ 6f483e8
... ... @@ -17,7 +17,7 @@
17 17  
18 18 link = link.replace('\n'," ").replace('\r'," ").replace('\'',"")
19 19  
20   - print link
  20 + # print link
21 21  
22 22 if len(link) < 5:
23 23 continue
... ... @@ -33,7 +33,7 @@
33 33 })
34 34  
35 35 elif self.isrpiki(link) :
36   - print link
  36 + # print link
37 37 data.append({
38 38 'bitly_url' : "",
39 39 'origin_url': str(link),
... ... @@ -121,7 +121,7 @@
121 121 datadb.fb_insert(sqlprefix + sqlvalues)
122 122 datadb.fb_insert(sqlreplace + sqlprefix[32:] + sqlvalues)
123 123  
124   -
  124 + print p_id + " done"
125 125 del(datadb)
126 126 del(insight)
... ... @@ -56,9 +56,9 @@
56 56 sqlprefix = sqlprefix[:len(sqlprefix) - 2] + ")"
57 57 sqlvalues = sqlvalues[:len(sqlvalues) - 2] + ");"
58 58  
59   - # print sqlprefix + sqlvalues
  59 + print sqlprefix + sqlvalues
60 60  
61   - datadb.fb_insert(sqlprefix + sqlvalues)
  61 + # datadb.fb_insert(sqlprefix + sqlvalues)
62 62  
63 63 del(datadb)
64 64 del(page_insight)