예제 #1
0
def get_article_link(begin, publisher, fakeid):
    url = article_list_url(begin, fakeid)
    # 获取json响应
    r = requests.get(url, headers=headers.get_cookie())
    # json转化为字典
    d = json.loads(r.content)
    log('d', type(d), d)
    app_msg_list = d['app_msg_list']
    # log('app-msg-list', app_msg_list)
    articles = []
    # 查询条目是否已经在数据库中,不在则插入,存在则更新
    for item in app_msg_list:
        # 转义不能用在文件名里的非法字符
        item['title'] = validate_title(item['title'])
        # 文件名为时间+标题+html
        time_prefix = formatted_time(item['create_time']).split(' ', 1)[0].replace('/', '')
        item['filename'] = time_prefix + '-' + item['title']
        item['publisher'] = publisher
        a = Article.one(aid=item['aid'])
        if a is None:
            a = Article.new(item)
        else:
            a.update(a.id, **item)
            break

        articles.append(a)
        # 返回article对象的列表
    return articles
예제 #2
0
def check_title_value(storyid):
    title = request.args.get('title')
    if title is None:
        return app.response_class(status=status.HTTP_204_NO_CONTENT)
    if utils.validate_title(title):
        return app.response_class(status=status.HTTP_200_OK)
    else:
        return app.response_class(status=status.HTTP_406_NOT_ACCEPTABLE)
예제 #3
0
 def validate_recipe_name(self):
     """
     Returns 'Valid' if recipe name is valid and recipe with similar recipe name
     has not been created by specific user or is related to specific recipe id related
     to specific category
     """
     if not self.recipe_name:
         return 'Please enter recipe name'
     elif not validate_title(self.recipe_name):
         return 'Please enter a valid recipe name'
     for recipe in self.recipes:
         if recipe.category_id == self.category_id and recipe.recipe_name.lower() == \
                 self.recipe_name.lower():
             if self.recipe_id and recipe.recipe_id == self.recipe_id:
                 return 'Valid'
             return 'A recipe with this recipe name is already available'
     return 'Valid'
예제 #4
0
 def validate_category_name(self):
     """
     Returns 'Valid' if category name is valid and category with similar category name
     has not been created by specific user or is related to specific category id related
     to specific user
     """
     if not self.category_name:
         return 'Please enter category name'
     elif not validate_title(self.category_name):
         return 'Please enter a valid category name'
     for category in self.categories:
         if category.user_id == self.user_id and category.category_name.lower() == \
                 self.category_name.lower():
             if self.category_id and category.category_id == self.category_id:
                 return 'Valid'
             return 'A category with this category name is already available'
     return 'Valid'
예제 #5
0
def create_story():
    token = get_token(request)
    if token is None:
        return app.response_class(status=status.HTTP_403_FORBIDDEN)
    values = request.json
    a = utils.validate_title(values['title'])
    if a:
        return app.response_class(status=status.HTTP_400_BAD_REQUEST,
                                  response=json.dumps({'error': a}),
                                  mimetype='application/json')
    title = utils.clean_title(values['title'])
    try:
        index = query(db.create_story, token, title)
        return app.response_class(status=status.HTTP_201_CREATED,
                                  response=json.dumps({'id': index}),
                                  mimetype='application/json')
    except DBError as e:
        return app.response_class(status=e.status,
                                  response=e.response,
                                  mimetype='application/json')
예제 #6
0
logger.debug('Started Sync')

if __name__ == "__main__":
    # url = 'https://salud.msp.gob.cu/'
    url = 'https://salud.msp.gob.cu/?feed=rss2'
    logger.debug(f'Requesting {url}')

    news_feed = feedparser.parse(url)

    if news_feed:
        for post in news_feed.entries:
            try:

                title = post.title
                if not validate_title(title):
                    continue

                content = post.content[0]['value']
                date = datetime.strptime(
                    time.strftime('%Y-%m-%d', post.published_parsed),
                    '%Y-%m-%d') - timedelta(days=1)
                logger.debug(f'Requesting {url}')
                date = date.strftime("%Y-%m-%d")

                dom = htmldom.HtmlDom()
                dom.createDom(html.unescape(content.replace('\n', ' ')))

                # Si existe el fichero ya el parte se ha registrado
                # if record_exist(date):
                if os.path.isfile(os.path.join(DUMP_DIRECTORY,