def index(): template_vars = _get_template_variables( li_index='active', news=get_news(get_locale(), items=3), categories=CATEGORIES, background_filename='img/about/header1.jpg', speakers=SPEAKERS) return render_template('index.html', **template_vars)
def news_category(category): if category not in CATEGORIES.keys(): abort(404) template_vars = _get_template_variables(li_news='active', categories=CATEGORIES, background='bkg-news') news = [] for item in get_news(get_locale()): if category in item['categories']: news.append(item) template_vars['news'] = news template_vars['category'] = category return render_template('news.html', **template_vars)
def get_word_cloud(query: str, start: str, end: str, picture_location: str, entities: bool): endpoint, key = getauth() news = get_news(query, start, end) df = pd.concat([news[:500], news[-500:]]) key_phrases = kp_request(df, endpoint, key) if entities: words = entities_request(key_phrases, ) else: words = " ".join(key_phrases) return generate_word_cloud(words, picture_location)
def get_data(i, num=0): """ Creates a list of (num) clean HTML news from page (i) (Stock symbol, news text and data) :param i: page number :param num: number of wanted news from page (i) :return: list of (Stock symbol, news text and data) """ containers = utils.get_news(i) news_list = list() for i in range(num + 1): s = utils.get_text(containers[i]) if s == "not a stock news": continue news_list.append(s) return news_list
def main(): news_sites = { 'm24.ru': M24_accidents, 'mosday.ru': Mosday_accidents, 'vm.ru': VM_accidents } # Инициализируем Наташу extractor = AddressExtractor() # Ищем новости, проверяем на наличие адресов, загружаем во временное хранилище news_list = [] for key in news_sites.keys(): news_list += get_news(news_sites, key, extractor) for item in news_list: if find_address_in_news(item, extractor): print(item)
def bot(): global DETECTED_LANGUAGE data = request.form incoming_msg = request.values.get('Body', '').lower() phone_number = data.get("From").replace("whatsapp:+", "") DETECTED_LANGUAGE = detect_language(incoming_msg) incoming_msg = translate_text( "en", incoming_msg) if DETECTED_LANGUAGE != "en" else incoming_msg response = MessagingResponse() if 'details' in incoming_msg and EVENT: translate_response = translate_text( DETECTED_LANGUAGE, str('Here is the link: ') ) if DETECTED_LANGUAGE != "en" else str('Here is the link: ') message = response.message(translate_response + STATIC_MESSAGE['link']) message.media(STATIC_MESSAGE['detailed_image']) return str(response) elif 'opt in' in incoming_msg or 'optin' in incoming_msg: send_notification(phone_number, 'Welcome_to_aa') elif 'news' in incoming_msg: result = get_news(incoming_msg) for i in result: response.message(i) return str(response) elif 'stats' in incoming_msg or 'statistics' in incoming_msg: result = get_stats(incoming_msg) response.message(result) return str(response) elif 'regulations' in incoming_msg: result = regulations(incoming_msg) response.message(result) return str(response) else: response_dialogFlow = detect_intent_from_text(str(incoming_msg), phone_number) translate_response = translate_text( DETECTED_LANGUAGE, str(response_dialogFlow.fulfillment_text) ) if DETECTED_LANGUAGE != "en" else str( response_dialogFlow.fulfillment_text) response.message(translate_response) return str(response)
def main(): news_sites = {'m24.ru': M24_accidents, 'mosday.ru': Mosday_accidents, 'vm.ru': VM_accidents} # Инициализируем Наташу morph_vocab = MorphVocab() extractor = AddrExtractor(morph_vocab) # Ищем новости, проверяем на наличие адресов, загружаем # во временное хранилище news_list = [] for key in news_sites.keys(): try: ScrapeClass = news_sites.get(key) source = ScrapeClass() rec = get_news(source, extractor) news_list += rec except (TypeError): print("Источник {} недоступен.".format(key)) for item in news_list: published = item['time'] + ' ' + item['date'] published = datetime.strptime(published, '%H:%M %d.%m.%Y') record = News( title=item['title'], link=item['link'], date_and_time=published, text=item['text'], address=item['location']['address'], street=item['location']['street'], lat=item['location']['coordinates'][0], lon=item['location']['coordinates'][1] ) record_in_db = News.query.filter_by(link=item['link']).first() if record_in_db: continue else: db.session.add(record) db.session.commit() '''
from utils import get_download_link, download_file, get_news, write_news_to_file, calculate_before_change if __name__ == "__main__": with open('companies.txt') as file: for line in file: company = line.strip() download_link = get_download_link(company) if not download_link: print(f'Company {company} was not found!') continue download_file(company, download_link) calculate_before_change(f'../files/{company}.csv', 3) news = get_news(company) write_news_to_file(company, news)
def get_template(input_text): endDate = datetime.today().strftime('%Y-%m-%d') startDate = (datetime.today() - timedelta(days=30)).strftime('%Y-%m-%d') if input_text == "[reset]": return TextSendMessage( text='你可以輸入任何人名,例如:蔡英文,我就會統計出他/她最近最常發生的事件種類, 並提供進一步查詢。', quick_reply=QuickReply( items=[ QuickReplyButton( action=MessageAction(label="蔡英文", text="蔡英文") ), QuickReplyButton( action=MessageAction(label="韓國瑜", text="韓國瑜") ), QuickReplyButton( action=MessageAction(label="郭台銘", text="郭台銘") )] )) elif ":" not in input_text: events = get_events(input_text, startDate, endDate) if len(events) == 0: return TextSendMessage( text='沒有這個人,或他/她的新聞數太少QAQ') elif len(events) <= 9: all_columns = [] all_actions = [] for i in range(len(events)): all_actions.append(MessageTemplateAction( label="...".join(events[i]['term'].split()) + " (" + str(events[i]["freq"]) + ")", text=input_text + ":" + events[i]['term'] )) if (i + 1) % 3 == 0: all_columns.append(CarouselColumn( title='{}相關新聞事件'.format(input_text), text='點選可獲得相關新聞', actions=all_actions )) all_actions = [] else: events = events[:8] all_columns = [] all_actions = [] for i in range(9): if i == 8: all_actions.append(MessageTemplateAction( label="more", text="更多事件" + ":" + str(8) + ":" + input_text )) else: all_actions.append(MessageTemplateAction( label="...".join(events[i]['term'].split()) + " (" + str(events[i]["freq"]) + ")", text=input_text + ":" + events[i]['term'] )) if (i + 1) % 3 == 0: all_columns.append(CarouselColumn( title='{}相關新聞事件'.format(input_text), text='點選可獲得相關新聞', actions=all_actions )) all_actions = [] buttons_template = TemplateSendMessage( alt_text='Carousel template', template=CarouselTemplate( columns=all_columns ) ) return buttons_template elif "更多事件" in input_text: _, id_event, input_text = input_text.split(":") id_event = int(id_event) events = get_events(input_text, startDate, endDate) action_lst = [] for i in range(3): action_lst.append(MessageTemplateAction( label="...".join(events[id_event + i]['term'].split()) + " (" + str(events[id_event]["freq"]) + ")", text=input_text + ":" + events[id_event + i]['term'] )) if len(events[id_event + 3:]) > 3: action_lst.append(MessageTemplateAction( label="more", text="更多事件" + ":" + str(id_event + 3) + ":" + input_text )) buttons_template = TemplateSendMessage( alt_text='Buttons Template', template=ButtonsTemplate( title='{}相關新聞事件'.format(input_text), text='點選可獲得相關新聞', actions=action_lst ) ) return buttons_template elif "more" in input_text: _, id, key, events = input_text.split(":") id = int(id) news = get_news(key, events, startDate, endDate) news_lst = news["data"][id:id + 3] id = id + 3 isMore = len(news["data"][id:]) != 0 flex_template = news_template_flex(news_lst, events, key, id, isMore) return flex_template else: key, events = input_text.split(":") news = get_news(key, events, startDate, endDate) news_lst = news["data"][:3] id = 3 isMore = len(news["data"]) > 3 flex_template = news_template_flex(news_lst, events, key, id, isMore) return flex_template
def json_news(): """ Fetches a single News article for display onscreen. :return: A rendered version of a markdown-formatted news article as json dump. """ return json.dumps(markdown(utils.get_news()))
def news(): template_vars = _get_template_variables(li_news='active', news=get_news(get_locale()), categories=CATEGORIES, background='bkg-news') return render_template('news.html', **template_vars)
LANGS = ('en', 'sk') TIME_FORMAT = '%Y-%m-%dT%H:%M:%S+00:00' app = Flask(__name__, static_url_path='/static') # pylint: disable=invalid-name app.config['BABEL_DEFAULT_LOCALE'] = 'sk' app.jinja_options = {'extensions': ['jinja2.ext.with_', 'jinja2.ext.i18n']} babel = Babel(app) # pylint: disable=invalid-name CATEGORIES = { 'conference': lazy_gettext('Conference'), 'media': lazy_gettext('Media'), 'speakers': lazy_gettext('Speakers'), } SPEAKERS = get_speakers() NEWS = get_news() @app.route('/sitemap.xml') def sitemap(): excluded = {'static', 'sitemap'} pages = [] for lang in LANGS: for rule in app.url_map.iter_rules(): if 'GET' in rule.methods and rule.endpoint not in excluded: # `url_for` appends unknown arguments as query parameters. # We want to avoid that when a page isn't localized. values = { 'lang_code': lang
import dash import dash_table import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Input, Output # Add State later # Remove indentation to avoid markdown not rendering from textwrap import dedent # Cryptocurrencies data cryptos = pd.read_csv('data/cryptos.csv') # url for news url = 'https://newsapi.org/v2/everything?q=cryptocurrency&sortBy=publishedAt&apiKey=e3e38edf30814dc18ef7f21a7fb9e775' # Get table of news data headlines = get_news(url) # Set dates start_date = pd.datetime(2018, 1, 1) end_date = pd.datetime.today() # Set window size and number of standard deviations (can make an input later!) window_size = 20 no_std_devs = 2 # Color scheme dictionary color = { 'background': '#C96567', 'text': 'white', 'div': '314455', 'plot': '#373737'
def get(self): major = request.args.get("major") return utils.get_news(major), 200