context.py 3.43 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
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import time


class Context() :

token = ""
contents_list = []
orderlist = [529491587137957,858096217617804,1670879929842831,1406069429705944,1531526667169602,
504207933048979,813554295420159,265757330288799,270103526524526,1702892339935231,
886456498082470,167968880220563,526019510826052,153258784853075,327293184069664,
497899983625735,415438118555115,147088008818887,502626173152828,171144389693855,
205240682996725,1440924922793255,119386554923285,500415013370641]

pagelist = {'529491587137957':'피키캐스트','858096217617804':'피키픽처스','1670879929842831':'피키예능촌',
'1406069429705944':'피키툰','1531526667169602':'피키키키키','504207933048979':'피키생활백서',
'265757330288799':'피키스토리','270103526524526':'곰들의반란','1702892339935231':'궁금청년',
'886456498082470':'우주인','167968880220563':'끔켬','526019510826052':'언어유희왕',
'327293184069664':'연애의모든것','497899983625735':'베스트비디오',
'415438118555115':'남자기때문에','147088008818887':'도기도기','502626173152828':'여자라면',
'171144389693855':'영화공장','813554295420159':'피키무비',
'153258784853075':'플레이','205240682996725':'어머이건봐야돼','1440924922793255':'메운여자',
'119386554923285':'당신의뇌를자극할이야기','500415013370641':'그곳에가고싶다'}


def __init__(self, token):
#print "context"
self.token = token.getToken()

def isNext(self,data):
if data['data'] == []:
return False
else:
return True

def nextUrl(self,data):
try:
return data['paging']['next']
except:
return ""

def setOrderList(self, list):
self.orderlist = list

def setPageList(self, dic):
self.pagelist = dic

def getPageList(self):
return self.pagelist

def getOrderList(self):
return self.orderlist


def setContextsFeed(self):

self.setContextsFeedAndTimestemp(0)

def setContextsFeedAll(self):

signed_max_int = 0x7fffffff - 1
self.setContextsFeedAndTimestemp(signed_max_int)

def setContextsFeedAndTimestemp(self,ts):

time_now = int(time.time())

return_val = []
for list in self.orderlist:
time.sleep(1)
url = 'https://graph.facebook.com/v2.6/%d/feed?'%list
print url + self.token
txt = requests.get(url + self.token).text
data = json.loads(txt)
return_val.append(data)
#print data

while self.isNext(data):
nextUrl = self.nextUrl(data)
#print nextUrl
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)

self.setContentsList(return_val)

def setContentsList(self, list):
for i in list:
#print i
for j in i['data']:
self.contents_list.append(j)

def getContentsList(self):
return self.contents_list