Esempio n. 1
0
    def upload_record(self, data):
        reader_dict = {
            '1门': '01',
            '2门': '02',
            '3门': '03',
            '4门': '04',
        }
        card = db.get_one_card(data['card_no'])
        if card is None:
            print('no card')
            return True
        device_no = f"{data['sn']}-{reader_dict[data['reader_no']]}"
        record_datetime = int(str2datetime(data['record_time'], format='%Y-%m-%d %H:%M:%S').timestamp()) * 1000

        url = self.taidii_base_url + '/api/attendance/attendance_device/card_attendance/'
        post_data = {
            'device_no': device_no,
            'attendance_list': [
                {
                    'people_id': card['people_id'],
                    'people_type': card['people_type'],
                    'record_datetime': record_datetime
                }
            ]
        }
        print(post_data)
        try:
            r = self.session.post(url, json=post_data)
        except:
            return False

        return True
Esempio n. 2
0
def get_question_and_agree(question_id, selector):
    try:
        question = Question()
        question.question_id = selector.xpath(
            '//div[@id="question_topic_editor"]/@data-id')[0]
        question.title = selector.xpath(
            '//div[@class="aw-mod-head"]/h1/text()')[0]
        question.people_id = selector.xpath(
            '//dd[@class="pull-left"]/a/@data-id')[0]
        task_filter('people', question.people_id)
        post_time_str = selector.xpath(
            '//div[@class="aw-question-detail-meta"]/div[1]/span[1]/text()'
        )[0].replace("发表时间 ", "")
        question.post_time = str2datetime(post_time_str)
        access_time_str = selector.xpath(
            '//div[@class="aw-side-bar-mod-body"]/ul/li[1]/span/text()')[0]
        question.access_time = str2datetime(access_time_str)
        question.read_num = selector.xpath(
            '//div[@class="aw-side-bar-mod-body"]/ul/li[2]/span/text()')[0]
        question.follow_num = selector.xpath(
            '//div[@class="aw-side-bar-mod-body"]/ul/li[3]/span/text()')[0]
        question.content = "".join(
            selector.xpath(
                '//div[contains(@class,"aw-question-detail-txt")]/text()'))
        CommonOper.add_one(question)
        CommonOper.add_filter_key("question_id", question_id)
        agrees = []
        agree_list = selector.xpath(
            '//div[@class="aw-question-detail-meta"]/p[contains(@class,"aw-agree-by")]/a/@data-id'
        )
        for p in agree_list:
            task_filter('people', p)
            agree = Agree()
            agree.question_id = question.question_id
            agree.people_id = p
            agrees.append(agree)
        CommonOper.add_all(agrees)
    except Exception as e:
        jsl_log.warning(
            "get question error,question_id:{},here are details {}".format(
                question_id, e))
Esempio n. 3
0
def get_people_and_follows(people_id, selector):
    try:
        people = People()
        people.people_id = people_id
        people.name = selector.xpath(
            '//div[@class="aw-user-center"]/div[1]/div/h1/text()')[0].strip()
        people.desc = "".join(
            selector.xpath(
                '//div[@class="aw-user-center"]/div[1]/div/span/text()'))
        if selector.xpath('//i[contains(@class,"i-user-locate")]'):
            user_locate = selector.xpath(
                '//i[contains(@class,"i-user-locate")]')[0].getparent()
            people.province = "".join(user_locate.xpath('a[1]/text()'))
            people.city = "".join(user_locate.xpath('a[2]/text()'))
        if selector.xpath('//i[contains(@class,"i-user-post")]'):
            user_post = selector.xpath(
                '//i[contains(@class,"i-user-post")]')[0].getparent()
            people.post = "".join(user_post.xpath('text()')).strip()
        if selector.xpath('//i[contains(@class,"i-user-visits")]'):
            user_visits = selector.xpath(
                '//i[contains(@class,"i-user-visits")]')[0].getparent()
            user_visits_str = "".join(user_visits.xpath('text()'))
            people.home_visit_num = re.findall('(\d+)', user_visits_str)[0]
        people_type_spans = selector.xpath(
            '//div[@class="aw-user-center"]/div[1]/div/p[3]/span')
        people.user_type = people_type_spans[0].xpath(
            'a/em/text()')[0].replace("»", "").strip()
        people.weiwang_num = people_type_spans[1].xpath('em/text()')[0]
        people.agree_num = people_type_spans[2].xpath('em/text()')[0]
        people.thanks_num = people_type_spans[3].xpath('em/text()')[0]
        people.gold_num = people_type_spans[4].xpath('em/text()')[0]
        if '+' in people.gold_num:
            people.gold_num = 100
        if selector.xpath('//span[contains(text(),"最后活跃")]'):
            last_active_time_str = selector.xpath(
                '//span[contains(text(),"最后活跃")]')[0].getparent().getnext(
                ).xpath('text()')[0]
            people.last_active_time = str2datetime(last_active_time_str)
        CommonOper.add_one(people)
        CommonOper.add_filter_key("people_id", people_id)
    except Exception as e:
        jsl_log.warning(
            "get people info error,people_id:{},here are details {}".format(
                people_id,
                format_tb(e.__traceback__)[0]))
    app.send_task("tasks.people.do_follow",
                  args=(
                      people_id,
                      0,
                  ),
                  queue="people_queue",
                  routing_key="people")
Esempio n. 4
0
 def parse_card(self, card_data):
     status_dict = {0: '正常状态', 1: '挂失', 2: '黑名单'}
     password = get_bcd_password(card_data[10:18])
     expire_time = str2datetime(
         card_data[18:28]).strftime('%Y-%m-%d %H:%M:%S')
     last_read = str2datetime(card_data[54:], format='%y%m%d%H%M%S')
     if last_read is not None:
         last_read = last_read.strftime('%Y-%m-%d %H:%M:%S')
     status_key = int(card_data[42:44], 16)
     return {
         'card_no': int(card_data[:10], 16),
         'password': password,
         'expire_time': expire_time,
         'date_range_code': card_data[28:36],
         'expire_count': int(card_data[36:40], 16),
         'permission': card_data[40:41],
         'privilege': card_data[41:42],
         'status': status_dict.get(status_key),
         'vocation_code': card_data[44:52],
         'in_out_flag': card_data[52:54],
         'last_read': last_read
     }
Esempio n. 5
0
def get_answer_comment(answer_id, selector):
    try:
        comment_list = selector.xpath('//ul/li')
        comment_id = 0
        answer_comments = []
        for c in comment_list:
            comment_id = comment_id + 1
            answer_comment = AnswerComment()
            answer_comment.answer_id = answer_id
            answer_comment.comment_id = comment_id
            answer_comment.people_id = c.xpath('div/a/@data-id')[0]
            task_filter('people', answer_comment.people_id)
            post_time_str = c.xpath('div/span/text()')[0]
            answer_comment.post_time = str2datetime(post_time_str)
            answer_comment.content = "".join(
                c.xpath('div/p[@class="clearfix"]/text()'))
            answer_comments.append(answer_comment)
        CommonOper.add_all(answer_comments)
    except Exception as e:
        jsl_log.warning(
            "get answer_comment_list error,answer_id:{},here are details {}".
            format(answer_id, e))
Esempio n. 6
0
def get_answers_and_agree(question_id, selector):
    try:
        answer_list = selector.xpath('//div[@class="aw-item"]')
        answers = []
        for a in answer_list:
            answer = Answer()
            answer.question_id = question_id
            answer.answer_id = a.xpath('@id')[0].split('_')[2]
            answer.answer_type = 1
            answer.people_id = a.xpath('a/@data-id')[0]
            task_filter('people', answer.people_id)
            answer.content = "".join(a.xpath('div/div/div[1]/div/text()'))
            post_time_str = a.xpath('div/div/div[2]/span/text()')[0]
            answer.post_time = str2datetime(post_time_str)
            answers.append(answer)
            answer_count_str = a.xpath('div/div/div[2]/a/text()')[0]
            answer_count = re.search('(\d+)', answer_count_str)
            if answer_count:
                app.send_task('tasks.question.do_answer_comment',
                              args=(answer.answer_id, ),
                              queue='answer_comment_queue',
                              routing_key='answer_comment')
            agrees = []
            agree_list = a.xpath('div/div/div[1]/p[2]/a/@data-id')
            for p in agree_list:
                task_filter('people', p)
                agree = Agree()
                agree.question_id = question_id
                agree.answer_id = answer.answer_id
                agree.people_id = p
                agrees.append(agree)
            CommonOper.add_all(agrees)
        CommonOper.add_all(answers)
    except Exception as e:
        jsl_log.warning(
            "get answer_list error,question_id:{},here are details {}".format(
                question_id, e))
Esempio n. 7
0
def newest(papers):
    return sorted(papers, reverse=True,
                  key=lambda x: str2datetime(x['time']))
Esempio n. 8
0
def newest(papers):
    return sorted(papers, reverse=True, key=lambda x: str2datetime(x['time']))
Esempio n. 9
0
        '/upvote/?', 'routes.item.Vote',
        '/search/?', 'routes.search.Search',
        '/rss/?', 'routes.rss.Rss',
        '/admin', 'waltz.modules.Analytics',
        '/login/?', 'routes.auth.Login',
        '/register/?', 'routes.auth.Register',
        '/logout/?', 'routes.auth.Logout',
        '/users/(.*)/?', 'routes.profiles.Profile',
        '/x/?', 'routes.auth.Register',
        '/404/?', 'routes.responses.NotFound',
        '/admin/?', 'routes.admin.Analytics',
        '/?', 'routes.index.Index',
        '(.*)', 'routes.responses.NotFound')

env = {'random': random,
       'time': lambda x: web.datestr(str2datetime(x),
                                     now=datetime.datetime.utcnow()),
       'karma': lambda: get_karma(waltz.session()['uname']),
       'voted': lambda pid: has_voted(waltz.session()['uname'], pid),
       'join': lambda x, y: y.join(x)
       }
sessions = SESSION_DEFAULTS
ssl = server['ssl'] if all(server['ssl']) else None
app = waltz.setup.dancefloor(urls, globals(), env=env, sessions=sessions,
                             db='%s/db/waltz' % os.getcwd(), ssl=ssl,
                             fcgi=server['type'], debug=server['debug'],
                             autoreload=False)

if __name__ == "__main__":
    app.run()
Esempio n. 10
0
from utils import str2datetime
from configs.config import server

urls = ('/submit/?', 'routes.submit.Submit', '/item/?', 'routes.item.Item',
        '/upvote/?', 'routes.item.Vote', '/search/?', 'routes.search.Search',
        '/rss/?', 'routes.rss.Rss', '/admin', 'waltz.modules.Analytics',
        '/login/?', 'routes.auth.Login', '/register/?', 'routes.auth.Register',
        '/logout/?', 'routes.auth.Logout', '/users/(.*)/?',
        'routes.profiles.Profile', '/x/?', 'routes.auth.Register', '/404/?',
        'routes.responses.NotFound', '/admin/?', 'routes.admin.Analytics',
        '/?', 'routes.index.Index', '(.*)', 'routes.responses.NotFound')

env = {
    'random': random,
    'time':
    lambda x: web.datestr(str2datetime(x), now=datetime.datetime.utcnow()),
    'karma': lambda: get_karma(waltz.session()['uname']),
    'voted': lambda pid: has_voted(waltz.session()['uname'], pid),
    'join': lambda x, y: y.join(x)
}
sessions = SESSION_DEFAULTS
ssl = server['ssl'] if all(server['ssl']) else None
app = waltz.setup.dancefloor(urls,
                             globals(),
                             env=env,
                             sessions=sessions,
                             db='%s/db/waltz' % os.getcwd(),
                             ssl=ssl,
                             fcgi=server['type'],
                             debug=server['debug'],
                             autoreload=False)
Esempio n. 11
0
    def parse_card_record(self, record_data):
        reader_dict = {
            '01': '1门',
            '02': '1门',
            '03': '2门',
            '04': '2门',
            '05': '3门',
            '06': '3门',
            '07': '4门',
            '08': '4门',
        }

        status_dict = {
            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: '合法卡开门—有效期即将过期',
        }

        return {
            'card_no':
            str(int(record_data[:10], 16)),
            'record_time':
            str2datetime(record_data[10:22],
                         format='%y%m%d%H%M%S').strftime('%Y-%m-%d %H:%M:%S'),
            'reader_no':
            reader_dict[record_data[22:24]],
            'reader_key':
            record_data[22:24],
            'status_desc':
            status_dict[int(record_data[24:], 16)],
            'status':
            int(record_data[24:], 16)
        }