def delete_photo(cookiefile, qqid, photo_json, sid): skey = get_cookie_value(cookiefile, "skey") gtk = get_gtk(skey) qqid = int(qqid) if qqid > 2000000000: url = DELETE_URL % gtk elif qqid > 1100000000: url = DELETE_URL2 % gtk elif qqid > 1000000000: url = DELETE_URL3 % gtk elif qqid < 200000000: url = DELETE_URL2 % gtk else: url = DELETE_URL4 % gtk data = generate_delete(qqid, photo_json['albumid'], photo_json['lloc']) logger.info("Deleting failed photo %s %s", qqid, url) result = post(url, data, cookiefile=cookiefile).decode('gbk').encode('utf8') logger.debug("Deleting %s result: %s", qqid, result) delete_json = extract_json_from_html(result, 'frameElement.callback') if (delete_json['code'] < 0): logger.warn("Deleting %s failed %s code %s, %s", qqid, delete_json['message'].encode('utf8'), delete_json['code'], delete_json['subcode']) if delete_json['code'] == -3000: log_paperboy('Need login(del) xks %s' % sid) return result
def post_shuoshuo(cookiefile, photofile, content, sid=0, schedule_ts=0, post_id=0): if type(cookiefile) is unicode: cookiefile = cookiefile.encode('utf8') if type(photofile) is unicode: photofile = photofile.encode('utf8') if type(content) is unicode: content = content.encode('utf8') qqid = 0 result = False try: qqid = get_cookie_value(cookiefile, "ptui_loginuin") photo_json = upload_photo2(cookiefile, photofile, qqid, sid) if photo_json.has_key('error'): logger.error("Post failed qq %s, xks %s, %s, %s, %s --> %s reason %s", qqid, sid, cookiefile, photofile, content, photo_json['error'], photo_json['msg'].encode('utf8')) log_post_error(post_id, "%s : %s" % (photo_json['error'], photo_json['msg'].encode('utf8'))) return False albumid = photo_json['albumid'] photoid = photo_json['lloc'] width = photo_json['width'] height = photo_json['height'] special_url = photo_json['micro']['url'] #TODO: save into wb_photojson if failed post_result = post_content(cookiefile, qqid, content, albumid, photoid, width, height, special_url, schedule_ts) #import pdb; pdb.set_trace() if (not schedule_ts and post_result.find("content_box") > 0): result = True elif schedule_ts: content_json = extract_json_from_html(post_result, 'frameElement.callback') if content_json['code'] < 0: logger.warn("Post failed qq %s, xks %s, %s, %s, %s, %s, %s, %s", qqid, sid, cookiefile, photofile, content, content_json['message'].encode('utf8'), content_json['code'], content_json['subcode']) log_post_error(post_id, "%s,%s : %s" % (content_json['code'], content_json['subcode'], content_json['message'].encode('utf8'))) if content_json['code'] == -3000: log_paperboy('Need login(content) xks %s' % sid) delete_photo(cookiefile, qqid, photo_json, sid) elif content_json.has_key('richinfo'): result = True else: logger.warn("Post failed qq %s, xks %s, %s, %s, %s", qqid, sid, cookiefile, photofile, content) delete_photo(cookiefile, qqid, photo_json, sid) log_post_error(post_id, "-2 : %s" % post_result) if (not schedule_ts and post_result.find("content_box") > 0) or (schedule_ts and post_result.find("richinfo") > 0): result = True except KeyboardInterrupt: raise except: logger.error("Post failed qq %s, xks %s, %s, %s, %s --> reason %s", qqid, sid, cookiefile, photofile, content, traceback.format_exc()) log_post_error(post_id, "-1 : exception" ) return result
def post_shuoshuo(cookiefile, photofile, content, sid=0, schedule_ts=0, post_id=0): if type(cookiefile) is unicode: cookiefile = cookiefile.encode('utf8') if type(photofile) is unicode: photofile = photofile.encode('utf8') if type(content) is unicode: content = content.encode('utf8') qqid = 0 result = False try: qqid = get_cookie_value(cookiefile, "ptui_loginuin") photo_json = upload_photo2(cookiefile, photofile, qqid, sid) if photo_json.has_key('error'): logger.error( "Post failed qq %s, xks %s, %s, %s, %s --> %s reason %s", qqid, sid, cookiefile, photofile, content, photo_json['error'], photo_json['msg'].encode('utf8')) log_post_error( post_id, "%s : %s" % (photo_json['error'], photo_json['msg'].encode('utf8'))) return False albumid = photo_json['albumid'] photoid = photo_json['lloc'] width = photo_json['width'] height = photo_json['height'] special_url = photo_json['micro']['url'] #TODO: save into wb_photojson if failed post_result = post_content(cookiefile, qqid, content, albumid, photoid, width, height, special_url, schedule_ts) #import pdb; pdb.set_trace() if (not schedule_ts and post_result.find("content_box") > 0): result = True elif schedule_ts: content_json = extract_json_from_html(post_result, 'frameElement.callback') if content_json['code'] < 0: logger.warn( "Post failed qq %s, xks %s, %s, %s, %s, %s, %s, %s", qqid, sid, cookiefile, photofile, content, content_json['message'].encode('utf8'), content_json['code'], content_json['subcode']) log_post_error( post_id, "%s,%s : %s" % (content_json['code'], content_json['subcode'], content_json['message'].encode('utf8'))) if content_json['code'] == -3000: log_paperboy('Need login(content) xks %s' % sid) delete_photo(cookiefile, qqid, photo_json, sid) elif content_json.has_key('richinfo'): result = True else: logger.warn("Post failed qq %s, xks %s, %s, %s, %s", qqid, sid, cookiefile, photofile, content) delete_photo(cookiefile, qqid, photo_json, sid) log_post_error(post_id, "-2 : %s" % post_result) if (not schedule_ts and post_result.find("content_box") > 0) or ( schedule_ts and post_result.find("richinfo") > 0): result = True except KeyboardInterrupt: raise except: logger.error("Post failed qq %s, xks %s, %s, %s, %s --> reason %s", qqid, sid, cookiefile, photofile, content, traceback.format_exc()) log_post_error(post_id, "-1 : exception") return result