Blame view

insight/context.py 3.43 KB
fa7135c35   System Administrator   first commit
1
2
3
4
5
6
7
8
9
10
  #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import requests
  import json
  import time
  
  
  class Context() :
  
      token = ""
40c655346   Noah   getContextsFeedAl...
11
      contents_list = []
fa7135c35   System Administrator   first commit
12
      orderlist = [529491587137957,858096217617804,1670879929842831,1406069429705944,1531526667169602,
c4df87d85   Leon   대상 페이지 추가 - 피키스토리
13
14
                   504207933048979,813554295420159,265757330288799,270103526524526,1702892339935231,
                   886456498082470,167968880220563,526019510826052,153258784853075,327293184069664,
4b7e09abb   Leon   add page : 어머이건봐야...
15
16
                   497899983625735,415438118555115,147088008818887,502626173152828,171144389693855,
                   205240682996725,1440924922793255,119386554923285,500415013370641]
fa7135c35   System Administrator   first commit
17
18
19
  
      pagelist = {'529491587137957':'피키캐스트','858096217617804':'피키픽처스','1670879929842831':'피키예능촌',
                  '1406069429705944':'피키툰','1531526667169602':'피키키키키','504207933048979':'피키생활백서',
c4df87d85   Leon   대상 페이지 추가 - 피키스토리
20
                  '265757330288799':'피키스토리','270103526524526':'곰들의반란','1702892339935231':'궁금청년',
fa7135c35   System Administrator   first commit
21
                  '886456498082470':'우주인','167968880220563':'끔켬','526019510826052':'언어유희왕',
fcab8f91d   Leon   del page : 너눈지, 영...
22
                  '327293184069664':'연애의모든것','497899983625735':'베스트비디오',
fa7135c35   System Administrator   first commit
23
                  '415438118555115':'남자기때문에','147088008818887':'도기도기','502626173152828':'여자라면',
fcab8f91d   Leon   del page : 너눈지, 영...
24
                  '171144389693855':'영화공장','813554295420159':'피키무비',
4b7e09abb   Leon   add page : 어머이건봐야...
25
26
                  '153258784853075':'플레이','205240682996725':'어머이건봐야돼','1440924922793255':'메운여자',
                  '119386554923285':'당신의뇌를자극할이야기','500415013370641':'그곳에가고싶다'}
fa7135c35   System Administrator   first commit
27
28
29
  
  
      def __init__(self, token):
c99dc50c3   Noah   getContextType 빼먹...
30
          #print "context"
c9e21b9c5   Noah   대시보드 프로젝트에서 분리
31
          self.token = token.getToken()
fa7135c35   System Administrator   first commit
32

40c655346   Noah   getContextsFeedAl...
33
34
35
36
37
38
39
40
41
42
43
      def isNext(self,data):
          if data['data'] == []:
              return False
          else:
              return True
  
      def nextUrl(self,data):
          try:
              return data['paging']['next']
          except:
              return ""
a047e6666   Noah   ㅇㅇ
44
45
      def setOrderList(self, list):
          self.orderlist = list
fa7135c35   System Administrator   first commit
46

a047e6666   Noah   ㅇㅇ
47
48
      def setPageList(self, dic):
          self.pagelist = dic
fa7135c35   System Administrator   first commit
49

a047e6666   Noah   ㅇㅇ
50
51
      def getPageList(self):
          return self.pagelist
fa7135c35   System Administrator   first commit
52

a047e6666   Noah   ㅇㅇ
53
54
      def getOrderList(self):
          return self.orderlist
fa7135c35   System Administrator   first commit
55

fa7135c35   System Administrator   first commit
56

40c655346   Noah   getContextsFeedAl...
57
      def setContextsFeed(self):
fa7135c35   System Administrator   first commit
58

40c655346   Noah   getContextsFeedAl...
59
          self.setContextsFeedAndTimestemp(0)
a047e6666   Noah   ㅇㅇ
60

40c655346   Noah   getContextsFeedAl...
61
      def setContextsFeedAll(self):
fa7135c35   System Administrator   first commit
62

40c655346   Noah   getContextsFeedAl...
63
64
          signed_max_int = 0x7fffffff - 1
          self.setContextsFeedAndTimestemp(signed_max_int)
fa7135c35   System Administrator   first commit
65

40c655346   Noah   getContextsFeedAl...
66
      def setContextsFeedAndTimestemp(self,ts):
fa7135c35   System Administrator   first commit
67
68
69
70
  
          time_now = int(time.time())
  
          return_val = []
57e30d996   Noah   context
71
          for list in self.orderlist:
fa7135c35   System Administrator   first commit
72
              time.sleep(1)
eb1b739be   suyoun   facebook graph ve...
73
74
              url = 'https://graph.facebook.com/v2.6/%d/feed?'%list
              print url + self.token
fa7135c35   System Administrator   first commit
75
76
77
              txt = requests.get(url + self.token).text
              data = json.loads(txt)
              return_val.append(data)
6156c772b   Noah   본문, 댓글 http://bit...
78
              #print data
fa7135c35   System Administrator   first commit
79

a047e6666   Noah   ㅇㅇ
80
81
              while self.isNext(data):
                  nextUrl = self.nextUrl(data)
2e4d69eb8   Noah   본문, 댓글 http://bit...
82
                  #print nextUrl
fa7135c35   System Administrator   first commit
83
84
85
86
87
88
                  feed_ts = int(nextUrl.split("until=")[1].split("&")[0])
                  if (time_now - ts) > feed_ts :
                      break
                  txt = requests.get(nextUrl).text
                  data = json.loads(txt)
                  return_val.append(data)
fa7135c35   System Administrator   first commit
89

40c655346   Noah   getContextsFeedAl...
90
          self.setContentsList(return_val)
a047e6666   Noah   ㅇㅇ
91

40c655346   Noah   getContextsFeedAl...
92
93
94
95
96
      def setContentsList(self, list):
          for i in list:
              #print i
              for j in i['data']:
                  self.contents_list.append(j)
fa7135c35   System Administrator   first commit
97

40c655346   Noah   getContextsFeedAl...
98
99
      def getContentsList(self):
          return self.contents_list