def get_by_path(self, path): link = Link.get_by_key_name(path) if link: return link try: id = base62.base62_decode(path) return Link.get_by_id(id) except: return None
def _image_exists(self, b62): if b62 is None: yield self.incr("not_found_counter") raise cyclone.web.HTTPError(404) uuid = base62_decode(b62) data = yield self.redis.exists(self.IMAGER_PREFIX % uuid) if data == 0: yield self.incr("not_found_counter") raise cyclone.web.HTTPError(404) defer.returnValue(data)
def _get_image_by_b62(self, b62): uuid = base62_decode(b62) img_path = yield self.redis.hget(self.IMAGER_PREFIX % uuid, 'path') mime = yield self.redis.hget(self.IMAGER_PREFIX % uuid, 'mime') yield self.redis.hincr(self.IMAGER_PREFIX % uuid, 'clicks') yield self.redis.zincrby(self.IMAGER_CLICK_RANKING, 1, b62) if img_path is None: defer.returnValue((None, None)) if mime is None or mime not in self.IMAGE_MIME_LIST: mime = mimetypes.guess_type(img_path)[0] yield self.redis.hset(self.IMAGER_PREFIX % uuid, 'mime', mime) defer.returnValue((mime, img_path))
def key_to_url(request, key, db): key = key.strip('/') if len(request.query) == 0 and len(key) == 5: code = base62_decode(key) url = code_to_url(code, db) if url: try: sp = SQLParams('named', 'format') sql = "UPDATE taobb_urls SET access_time = now(), gmt_modified = now() , access_count = access_count + 1 WHERE id=:id LIMIT 1" sql, params = sp.format(sql, {'id': code, }) db.execute(sql, params) except: pass return url return None
def _get_image_data(self, b62): uuid = base62_decode(b62) data = yield self.redis.hgetall(self.IMAGER_PREFIX % uuid) del(data["path"]) del(data["uploader_addr"]) defer.returnValue(cyclone.escape.json_encode(data))
def _dislike(self, b62): uuid = base62_decode(b62) v = yield self.redis.hincrby(self.IMAGER_PREFIX % uuid, 'dislikes', 1) yield self.redis.zincrby(self.IMAGER_DISLIKE_RANKING, 1, b62) defer.returnValue(v)
def test_base62(self): self.assertEqual(base62_encode(100), '1C') self.assertEqual(base62_encode(999999999), '15FTGf') self.assertEqual(base62_decode('dtvd3o'), 12345678910)
def test_base_decode(self): integer = base62.base62_decode('3d7'); print(integer) self.assertTrue(integer)
from weibo_api import api import csv import time import sys ''' Step 0: automatically get authorization by oauth2.0 ''' api = api() ''' Step 1: get the repost_timeline ''' """The target weibo: http://www.weibo.com/2099181812/ybI0dopBD """ from base62 import base62_decode # import base62 module mid = 'ybI0dopBD' # input the mid here id1 = base62_decode(mid[:1]) id2 = base62_decode(mid[1:-4]) id3 = base62_decode(mid[5:]) numList = [id1, id2, id3] id = int(''.join(map(str, numList))) print id """get the repost_count""" for object in api.counts(ids=id): repost_count = object.__getattribute__('rt') print repost_count pages = repost_count / 200 + 2 # why should it be 2? cuz python starts from 0 # import csv # addressForSavingData= "C:/Python27/weibo/Weibo_repost/repostSave.csv" # file = open(addressForSavingData,'wb') # save to csv file # for page in range(1, pages):
from weibo_api import api import csv import time import sys ''' Step 0: automatically get authorization by oauth2.0 ''' api=api() ''' Step 1: get the repost_timeline ''' """The target weibo: http://www.weibo.com/2099181812/ybI0dopBD """ from base62 import base62_decode # import base62 module mid='ybI0dopBD' # input the mid here id1=base62_decode(mid[:1]) id2=base62_decode(mid[1:-4]) id3=base62_decode(mid[5:]) numList=[id1, id2, id3] id=int(''.join(map(str,numList))) print id """get the repost_count""" for object in api.counts(ids=id): repost_count=object.__getattribute__('rt') print repost_count pages= repost_count/200 +2 # why should it be 2? cuz python starts from 0 # import csv # addressForSavingData= "C:/Python27/weibo/Weibo_repost/repostSave.csv"