Exemplo n.º 1
0
 def get_list_by_page(self, **arg):
     '''分页获取数据'''
     _param = self._get_where(Dict(arg))
     _limit = self._get_limit(Dict(arg).page)
     return self.db_s.query("SELECT a.`id`, a.`u_name`, a.`create_time`,\
                           a.`email`, a.`status` \
                           FROM `users` a \
                           INNER JOIN (SELECT `id` FROM `users` WHERE 1=1 %s \
                           ORDER BY `create_time` DESC %s) t ON a.`id`=t.`id`\
                           " % (_param, _limit))
Exemplo n.º 2
0
 def get_list_by_page(self, **arg):
     '''分页获取数据'''
     _param = self._get_where(Dict(arg))
     _limit = self._get_limit(Dict(arg).page)
     return self.db_s.query("SELECT a.`id`, a.`value`, a.`create_time`,\
                           a.`type` \
                           FROM `black_list` a \
                           INNER JOIN (SELECT `id` FROM `black_list` WHERE 1=1 %s \
                           ORDER BY `create_time` DESC %s) t ON a.`id`=t.`id`\
                           " % (_param, _limit))
 def _insert_comment(self, comment):
     '''插入评论'''
     _list = []
     for item in comment["comments"]:
         _i = Dict(item)
         _u = Dict(_i.user)
         _s = Dict(_i.status)
         _list.append(
             (_i.id, _s.id, _i.text, _u.id, int(_i.mid), _u.screen_name,
              formattime(_i.created_at)))
     CommentsService.insert(_list)
Exemplo n.º 4
0
 def get_list_by_page(self, admin=None, **arg):
     '''分页获取数据'''
     _param = self._get_where(Dict(arg), admin)
     _limit = self._get_limit(Dict(arg).page)
     return self.db_s.query("SELECT a.`id`, a.`text`, a.`user_name`, a.`create_date`,\
                           a.`bmiddle_pic`, a.`source`,\
                           a.`thumbnail_pic`, a.`likes`, \
                           a.`height`, a.`views`, a.`comments`, a.`height`, a.`width` \
                           FROM `pics` a \
                           INNER JOIN (SELECT `id` FROM `pics` WHERE 1=1 AND `height`>0 %s \
                           ORDER BY `create_date` DESC %s) t ON a.`id`=t.`id`\
                           " % (_param, _limit))
Exemplo n.º 5
0
 def _get_data_from_sina(self):
     '''获取新浪微博的数据'''
     _url_list = []
     _data_list = []
     _keywords = get_keywords().split(',')
     try:
         for keyword in _keywords:
             if 'SERVER_SOFTWARE' in os.environ:
                 url = 'http://api.t.sina.com.cn/trends/statuses.json?count=40&source=%s&trend_name=%s' % (
                     get_appkey(), keyword)
                 url = url.encode('utf-8')
                 url = urllib2.unquote(url)
                 items = json.loads(urllib2.urlopen(url).read())
             else:
                 items = json.loads(
                     requests.get(
                         'http://api.t.sina.com.cn/trends/statuses.json?count=40&source=%s&trend_name=%s'
                         % (get_appkey(), keyword)).content)
             for item in items:
                 i = Dict(item)
                 if not i.thumbnail_pic:
                     continue
                 _url_id = url2id(i.thumbnail_pic)
                 _url_list.append(str(_url_id))
                 _dic = {str(_url_id): item}
                 _data_list.append(_dic)
     except Exception, what:
         return what
 def get_by_pid(self, **arg):
     '''根据图片ID获取评论'''
     _arg = Dict(arg)
     return self.db.query(
         "SELECT `id`, `text`, `user_id`, `mid`, `user_name`, `create_date` \
                        FROM `comments` WHERE `p_id`=%s ORDER BY `create_date` DESC",
         _arg.id)
Exemplo n.º 7
0
 def get_by_id(self, **arg):
     '''根据ID获取图片'''
     _arg = Dict(arg)
     self._update_pic_view(id=_arg.id)
     return self.db.get("SELECT `id`, `text`, `user_name`, `create_date`,\
                        `original_pic`, `source`, `likes`, \
                        `height`, `views`, `comments`, `height`, `width` \
                        FROM `pics` WHERE `id`=%s", _arg.id)
Exemplo n.º 8
0
 def insert(self, **arg):
     '''新增图片'''
     _arg = Dict(arg)
     if _arg.status:
         _status = _arg.status
     else:
         _status = 2
     return self.db.execute("INSERT INTO `pics` (`id`, `user_id`, `text`, `user_name`, `create_date`, `thumbnail_pic`, `bmiddle_pic`, `original_pic`, `profile_image_url`, `url_id`, `source`, `status`, `width`, `height`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", _arg.id, _arg.user_id, _arg.text, _arg.user_name, _arg.create_date, _arg.thumbnail_pic, _arg.bmiddle_pic, _arg.original_pic, _arg.profile_image_url, _arg.url_id, _arg.source, _status, _arg.width, _arg.height)
 def get_active_client(cls):
     '''获取可执行的client'''
     _cookie = get_token_from_cookie()
     if _cookie:
         r = Dict(json.loads(_cookie))
         client = APIClient(app_key=wb.app_key,
                            app_secret=wb.app_secret,
                            redirect_uri=wb.redirect_uri)
         client.set_access_token(r.access_token, r.expires_in)
         return client
     _url = cls().get_weibo_login_url()
     return dict(done=False, url=_url, message=u'需要登录')
Exemplo n.º 10
0
 def add(cls):
     '''抓取新浪微博数据'''
     items = cls()._get_data_from_sina()
     _black_list = BlackListService.get_all_black()
     _status = 2  #默认数据是未审核
     if not items:
         return "None"
     for item in items:
         i = Dict(item)
         u = Dict(i.user)
         _is_in_black = False
         for _black in _black_list:
             if (_black["type"] == 0 and int(_black["value"]) == u.id) or (
                     _black["type"] == 1 and _black["value"] in i.text):
                 _is_in_black = True
                 continue
         if _is_in_black:
             continue
         try:
             _img = get_remote_image_width_height(i.thumbnail_pic)
             _width = _img[0]
             _height = int(_img[1] * 255 / _img[0])
             PicsHandler().insert(id=i.id,
                                  user_id=u.id,
                                  text=i.text,
                                  user_name=u.name,
                                  create_date=formattime(i.created_at),
                                  thumbnail_pic=i.thumbnail_pic,
                                  bmiddle_pic=i.bmiddle_pic,
                                  original_pic=i.original_pic,
                                  profile_image_url=u.profile_image_url,
                                  url_id=url2id(i.thumbnail_pic),
                                  source=1,
                                  status=_status,
                                  height=_height,
                                  width=_width)
         except:
             continue
     return "Success %s" % len(items)
Exemplo n.º 11
0
def user_login(**arg):
    '''用户登录成功记录Cookie'''
    _arg = Dict(arg)
    _uid = str(_arg.uid)
    _salt = short_by_hex(_uid)[1]
    _hash = hashlib.md5('%s%s' % (_uid, _salt)).hexdigest()
    response.set_cookie('user_id',
                        _uid,
                        secret=SECRET,
                        path='/',
                        domain=COOKIE_DOMAIN)
    response.set_cookie('user_hash',
                        _hash,
                        secret=SECRET,
                        path='/',
                        domain=COOKIE_DOMAIN)
Exemplo n.º 12
0
 def delete_pic(self, **arg):
     '''删除图片'''
     _arg = Dict(arg)
     return self.db.execute_rowcount("UPDATE `pics` SET `status`=0 WHERE `id` IN (%s)"%_arg.ids)
Exemplo n.º 13
0
 def pass_user(self, **arg):
     '''用户审核通过'''
     _arg = Dict(arg)
     return self.db.execute_rowcount(
         "UPDATE `users` SET `status`=1 WHERE `id` IN (%s)" % _arg.ids)
Exemplo n.º 14
0
 def check_is_registered(self, **arg):
     '''检查email是否已经注册'''
     _arg = Dict(arg)
     return self.db.get("SELECT `id` FROM `users` WHERE `email`=%s",
                        _arg.email)
Exemplo n.º 15
0
 def insert(self, **arg):
     '''新增用户'''
     _arg = Dict(arg)
     return self.db.execute_lastrowid(
         "INSERT INTO `users` (`u_name`, `pwd`, `email`, `status`) VALUES (%s, %s, %s, 0)",
         _arg.u_name, _arg.pwd, _arg.email)
Exemplo n.º 16
0
 def pass_pic(self, **arg):
     '''通过审核图片'''
     _arg = Dict(arg)
     return self.db.execute_rowcount("UPDATE `pics` SET `status`=1 WHERE `id` IN (%s)"%_arg.ids)
Exemplo n.º 17
0
 def get_prev(self, **arg):
     '''获取上一张图片'''
     _arg = Dict(arg)
     return self.db.get("SELECT `id`, `text`, `user_name` FROM `pics` WHERE `create_date`>%s AND `status`=1 ORDER BY `create_date` ASC LIMIT 1", _arg.create_date)
Exemplo n.º 18
0
 def delete_black_list(self, **arg):
     '''删除黑名单信息'''
     _arg = Dict(arg)
     return self.db.execute_rowcount(
         "DELETE FROM `black_list` WHERE `id` IN (%s)" % _arg.ids)
Exemplo n.º 19
0
 def check_is_exist(self, **arg):
     '''查找黑名单是否已经存在'''
     _arg = Dict(arg)
     return self.db.get(
         "SELECT `id` FROM `black_list` WHERE `value`=%s AND `type`=%s",
         _arg.bValue, _arg.bType)
Exemplo n.º 20
0
 def get_black_by_id(self, **arg):
     '''查找黑名单信息'''
     _arg = Dict(arg)
     return self.db.get(
         "SELECT `value`, `type` FROM `black_list` WHERE `id`=%s", _arg.bid)
Exemplo n.º 21
0
 def update_pic_likes(self, **arg):
     '''更新图片likes次数'''
     _arg = Dict(arg)
     return self.db.execute_rowcount("UPDATE `pics` SET `likes`=`likes`+1 WHERE `id`=%s", _arg.id)
Exemplo n.º 22
0
 def get_count(self, **arg):
     '''获取所有数量'''
     _param = self._get_where(Dict(arg))
     return self.db_s.get(
         'SELECT COUNT(*) AS numb FROM `black_list` WHERE 1=1 %s' %
         _param)['numb']
Exemplo n.º 23
0
 def _update_pic_view(self, **arg):
     '''更新图片浏览次数'''
     _arg = Dict(arg)
     return self.db.execute_rowcount("UPDATE `pics` SET `views`=`views`+1 WHERE `id`=%s", _arg.id)
Exemplo n.º 24
0
 def insert(self, **arg):
     '''新增黑名单'''
     _arg = Dict(arg)
     return self.db.execute_lastrowid(
         "INSERT INTO `black_list` (`value`, `type`) VALUES (%s, %s)",
         _arg.bValue, _arg.bType)
Exemplo n.º 25
0
 def get_count(self, admin=None, **arg):
     '''获取所有数量'''
     _param = self._get_where(Dict(arg), admin)
     return self.db_s.get('SELECT COUNT(*) AS numb FROM `pics` WHERE 1=1 AND `height`>0 %s'%_param)['numb']
Exemplo n.º 26
0
 def get_by_key(self, **arg):
     '''根据key获取配置'''
     _arg = Dict(arg)
     return self.db.get(
         "SELECT `id`, `key`, `value`, `create_date` \
                        FROM `options` WHERE `key`=%s", _arg.option_key)
Exemplo n.º 27
0
from .options_services import get_option
import urllib, json


def get_site_url():
    return get_option('site_url', '/')


def get_weibo():
    return dict(app_key=get_option('comment_appkey', 2891867310),
                app_secret=get_option('comment_secret',
                                      '07435de07c9a9472d5146c706e92ffa7'),
                redirect_uri='%scallback?' % get_site_url())


wb = Dict(get_weibo())


def set_token_to_cookie(r):
    '''保存weibo的token'''
    _cookie = json.dumps(
        dict(access_token=r.access_token, expires_in=r.expires_in))
    response.set_cookie('access_token',
                        _cookie,
                        secret=SECRET,
                        path='/',
                        domain=COOKIE_DOMAIN,
                        expires=r.expires_in)


def get_token_from_cookie():
Exemplo n.º 28
0
 def update(self, **arg):
     '''更新内容'''
     _arg = Dict(arg)
     return self.db.execute_rowcount(
         "UPDATE `options` SET `value`=%s, `update_date`=FROM_UNIXTIME(UNIX_TIMESTAMP(),'%%Y-%%m-%%d %%H:%%i:%%s') WHERE `key`=%s",
         _arg.option_value, _arg.option_key)
Exemplo n.º 29
0
 def insert(self, **arg):
     '''新增配置'''
     _arg = Dict(arg)
     return self.db.execute_rowcount(
         "INSERT INTO `options` (`key`, `value`, `update_date`) VALUES (%s, %s, FROM_UNIXTIME(UNIX_TIMESTAMP(),'%%Y-%%m-%%d %%H:%%i:%%s'))",
         _arg.option_key, _arg.option_value)
Exemplo n.º 30
0
 def get_user_by_id(self, **arg):
     '''查找用户信息'''
     _arg = Dict(arg)
     return self.db.get(
         "SELECT `pwd`, `status`, `email` FROM `users` WHERE `id`=%s",
         _arg.uid)