def begin(): client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL) code = get_code() r = client.request_access_token(code) print r access_token = r.access_token # 新浪返回的token,类似abc123xyz456 expires_in = r.expires_in # token过期的UNIX时间 client.set_access_token(access_token, expires_in) #发普通微博 data = t2.Now() num = u"咚~"*(data[0]%12) if num == "": num = u"咚~"*12 time.sleep(data[1]) #client.statuses.update.post(status=num) #私人需求 head = {"Authorization":"OAuth2 "+access_token} DB = os.listdir(os.path.split(os.path.realpath(__file__))[0]+"/DB") Need = GetPage(head,Self,Target) for j in Need: if str(j[0])+".json" not in DB: Data = json.dumps(j[1]) f = open(os.path.split(os.path.realpath(__file__))[0]+"/DB/"+str(j[0])+".json","w") f.write(Data) f.close() try: for i in json.loads(Data)["pic_urls"]: for img in i.values(): GetImg(os.path.split(os.path.realpath(__file__))[0]+"/DB/"+str(j[0])+"--"+os.path.split(img)[1],re.sub("(/bmiddle/)|(/thumbnail/)","/large/",img)) except: pass if eml.send_mail(["*****@*****.**"],"SomeOne Update a MicroBlog","It happened @ "+j[1]["created_at"]+"\n"+j[1]["text"]): print "Mail Sent" else: print "Mail Sent Failed"
qus = Data[1].text if i.attrib['data-type'] == 'a': Type = "agree an answer in" flag = 2 if len(content[0].xpath(u'a'))>2: Type = "answer a question" qus = Data[2].text flag = 3 ans = "" if flag: ans = i.xpath(u"div[@class='zm-item-answer ']/div[@class='zm-item-rich-text']/textarea")[0].text JSON_Arr.append( {"TimeStamp":TS,"Time":T,"Type":Type,"Question":qus,"Answer":ans}) return JSON_Arr def GetNew(): request = urllib2.Request(url,headers=header) return urllib2.urlopen(request).read() Arr = Get_Acti(GetNew()) DB = os.listdir(os.path.split(os.path.realpath(__file__))[0]+"/DB") MsgQuene = [] for i in Arr: if (str(i["TimeStamp"])+".json" not in DB) : f = open(os.path.split(os.path.realpath(__file__))[0]+"/DB/%s.json"%(i["TimeStamp"]),"w") f.write(json.dumps(i)) f.close() MsgQuene.append(i) for i in MsgQuene: if eml.send_mail(["*****@*****.**"],"SomeOne "+i["Type"]+" "+i["Question"],"It happened @ "+str(i["Time"])+"\n"+re.sub("\<br\>","\n",i["Answer"])): #if 1: print "Mail Sent" else: print "Mail Sent Error"