def ticket_task(self, datetime, from_station='SHH', to_station='GIW'): url = 'https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate=2016-09-28&from_station=SHH&to_station=GIW' res = requests.get(url, verify=False) if res and res.status_code == 200: result = json.loads(res.text) k739_train = filter(lambda x: x.get('station_train_code') == "K739", result.get('data').get('datas')) if k739_train: train_info = k739_train[0] yw_num = train_info.get('yw_num') canwebby = train_info.get('canWebBuy') yz_num = train_info.get('yz_num') body = u""" 硬卧:%s 可购买:%s 硬座数量:%s """ % (yw_num, canwebby, yz_num) task_logger.info(body) if yw_num != u'无': url = 'http://192.168.2.14:9002/weixin/message/send' data = dict(user='******', content={"content": body}, appid=5) res = requests.post(url, json=data) return res.text if res else 'error'
def _new_user_group_association(user: model.auth.User, group: model.group.Group): association = model.group.ResourceGroupAssociation( group_id=group.id, resource_id=user.id, resource_type=model.misc.ResourceType.user, ) model.conn.add(association) log.info(f'Associated user {user.username!r} to group {group.name!r}') return association
def task1(self, url): task_logger.info(url) try: res = requests.get(url, timeout=5) assert res.status_code == 200 task_logger.debug(res.text) pass except Exception as e: raise self.retry(countdown=back_off(self.max_retries), max_retries=5) return url
def _delete_user_group_association(user: model.auth.User, group: model.group.Group): association: model.group.ResourceGroupAssociation = model.group.ResourceGroupAssociation.query( ).filter_by( group_id=group, resource_id=user.id, resource_type=model.misc.ResourceType.user, ).first() if association: model.conn.delete(association) user_model: model.auth.User = model.auth.User.query().filter_by( id=association.resource_id).first() user = user_model.username if user_model else association.resource_id log.info( f'Removed user {user!r} from group {association.group.name!r}')
def authenticate(self, username: str, password: str) -> bool: manager = self.load_manager() try: user_data = manager.authenticate_user(username=username, password=password) except Exception as exc: log.info( f'LDAP user authentication failed with {type(exc).__name__} error: {exc}' ) return False user_model = model.auth.User.query().filter_by( username=user_data.username).first() if not user_model: user_model = self._new_user(username=user_data.username) self._synchronize_user_model(user_model=user_model, user_data=user_data) model.conn.commit() return True
def _new_group(group_name): group = model.group.Group(name=group_name) model.conn.add(group) log.info(f'Created new group {group!r}') return group
def _new_user(cls, username): user_model = model.auth.User(username=username, auth_provider=cls.name()) model.conn.add(user_model) log.info(f'Created new user model for user {username!r}') return user_model
def task1(self, url): task_logger.info(url) return url