Bot #186
1571
documentation/telegram_bot/api_handling/api_handler.html
Normal file
1571
documentation/telegram_bot/api_handling/api_handler.html
Normal file
File diff suppressed because it is too large
Load Diff
65
documentation/telegram_bot/api_handling/index.html
Normal file
65
documentation/telegram_bot/api_handling/index.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.api_handling API documentation</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>telegram_bot.api_handling</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-submodules">Sub-modules</h2>
|
||||
<dl>
|
||||
<dt><code class="name"><a title="telegram_bot.api_handling.api_handler" href="api_handler.html">telegram_bot.api_handling.api_handler</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for communicating with webservice to get data from database</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot" href="../index.html">telegram_bot</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-submodules">Sub-modules</a></h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.api_handling.api_handler" href="api_handler.html">telegram_bot.api_handling.api_handler</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
1810
documentation/telegram_bot/bot.html
Normal file
1810
documentation/telegram_bot/bot.html
Normal file
File diff suppressed because it is too large
Load Diff
507
documentation/telegram_bot/bot_updates.html
Normal file
507
documentation/telegram_bot/bot_updates.html
Normal file
@ -0,0 +1,507 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.bot_updates API documentation</title>
|
||||
<meta name="description" content="script for regularly sending updates on shares and news based on user interval" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>telegram_bot.bot_updates</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>script for regularly sending updates on shares and news based on user interval</p>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">"""
|
||||
script for regularly sending updates on shares and news based on user interval
|
||||
"""
|
||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
||||
__date__ = "10.05.2022"
|
||||
__version__ = "1.0.2"
|
||||
__license__ = "None"
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler # scheduler for cron
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import telegram_bot.helper_functions as hf
|
||||
import telegram_bot.news.news_fetcher as news_fetcher
|
||||
import telegram_bot.shares.share_fetcher as share_fetcher
|
||||
from telegram_bot.api_handling.api_handler import API_Handler
|
||||
from telegram_bot.bot import bot
|
||||
|
||||
'''
|
||||
* * * * * code
|
||||
┬ ┬ ┬ ┬ ┬
|
||||
│ │ │ │ │
|
||||
│ │ │ │ └──── weekday (0->Monday, 7->Sunday)
|
||||
│ │ │ └────── Month (1-12)
|
||||
│ │ └──────── Day (1-31)
|
||||
│ └────────── Hour (0-23)
|
||||
└──────────── Minute (0-59)
|
||||
|
||||
example 0 8 * * * -> daily update at 8am
|
||||
'''
|
||||
user_ids = []
|
||||
user_crontab = []
|
||||
|
||||
load_dotenv(dotenv_path='.env')
|
||||
|
||||
|
||||
def start_updater():
|
||||
""" starting function for regularly sending updates
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
print("Bot updates started")
|
||||
|
||||
my_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD")))
|
||||
|
||||
update_crontab(my_handler)
|
||||
|
||||
|
||||
def update_crontab(p_my_handler):
|
||||
""" Updating crontab lists every hour
|
||||
:type pCurrent_Time: time when starting crontab update
|
||||
:param pCurrent_Time: datetime
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
global user_crontab
|
||||
global user_ids
|
||||
|
||||
all_users = p_my_handler.get_all_users() # get all users so crontabs can update for everybody
|
||||
|
||||
user_ids = []
|
||||
user_crontab = []
|
||||
|
||||
for element in all_users:
|
||||
if element["cron"] != '' and element["telegram_user_id"] != '': # check if both values are existing so I have consistent data
|
||||
try:
|
||||
user_ids.append(int(element["telegram_user_id"]))
|
||||
try:
|
||||
user_crontab.append(str(element["cron"]))
|
||||
except:
|
||||
user_ids.pop() # if something goes wrong with cron I have to delete matching user id
|
||||
except: continue
|
||||
|
||||
|
||||
print(user_ids)
|
||||
|
||||
update_based_on_crontab(user_ids, user_crontab, p_my_handler)
|
||||
|
||||
update_crontab(p_my_handler) # restart the update after time sleep
|
||||
|
||||
|
||||
def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler):
|
||||
""" Check all the crontab codes and add jobs to start in time
|
||||
:type p_user_ids: array
|
||||
:param p_user_ids: user id array of all users
|
||||
|
||||
:type p_user_crontab: array
|
||||
:param p_user_crontab: crontabs for all users equivalent to the user array
|
||||
|
||||
:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: get database stuff
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
my_scheduler = BackgroundScheduler() # schedule sends based on cron
|
||||
|
||||
for i in range(len(p_user_ids)):
|
||||
cron_split = p_user_crontab[i].split(" ") # split it up to use in scheduler
|
||||
print(cron_split[4], cron_split[1], cron_split[0], cron_split[3], cron_split[2])
|
||||
my_scheduler.add_job(update_for_user, 'cron', day_of_week=cron_split[4], hour=cron_split[1], minute=cron_split[0], month=cron_split[3], day=cron_split[2], args=(p_user_ids[i], p_my_handler))
|
||||
|
||||
my_scheduler.start()
|
||||
|
||||
time.sleep( 600 ) # scheduler runs in background and I wait 10mins
|
||||
my_scheduler.shutdown() # after this the new crontabs will be loaded
|
||||
|
||||
def update_for_user(p_user_id, p_my_handler):
|
||||
""" Pull shares and send updates for specific user id
|
||||
:type p_user_id: integer
|
||||
:param p_user_id: user id of user that shall receive update
|
||||
|
||||
:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: handle the api and pull from database
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
share_symbols = []
|
||||
share_amounts = []
|
||||
|
||||
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) # get all existing shares for user
|
||||
|
||||
for element in my_portfolio:
|
||||
if element["count"] != '' and element["isin"] != '':
|
||||
print(element["count"], element["isin"])
|
||||
share_symbols.append(element["isin"])
|
||||
share_amounts.append(element["count"])
|
||||
|
||||
my_user = p_my_handler.get_user(p_user_id)
|
||||
send_to_user("Hello %s this is your share update for today:"%str(my_user["username"]), pUser_id=p_user_id)
|
||||
|
||||
shares = p_my_handler.get_user_shares(p_user_id) # all interest shares
|
||||
|
||||
if len(share_symbols) != 0: # iterate through all shares
|
||||
for i in range(len(share_symbols)):
|
||||
my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
|
||||
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(share_amounts[i])}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
|
||||
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
|
||||
else:
|
||||
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id)
|
||||
|
||||
if len(shares) != 0: # Send updates on watchlist shares if existing
|
||||
send_to_user("Your watchlist shares:", pUser_id=p_user_id)
|
||||
for element in shares:
|
||||
send_to_user(share_fetcher.get_share_information_markdown(element), pUser_id=p_user_id, md_mode=True)
|
||||
|
||||
keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array
|
||||
|
||||
if (keywords): # if keywords exist and array is not empty
|
||||
send_to_user("If you haven't read yet: \nHere are some interesting news according to your keywords:", pUser_id=p_user_id)
|
||||
for keyword in keywords:
|
||||
news = news_fetcher.get_top_news_by_keyword(keyword)["articles"]
|
||||
keyword = hf.make_markdown_proof(keyword)
|
||||
|
||||
if not news: # if empty news array
|
||||
send_to_user(f"No news found for keyword _{keyword}_\.", pUser_id=p_user_id, md_mode=True)
|
||||
|
||||
elif news == None: # if news is none
|
||||
send_to_user(f"Server error for keyword _{keyword}_\.", pUser_id=p_user_id, md_mode=True)
|
||||
else:
|
||||
news_formatted = news_fetcher.format_article(news[0]) # format for message, only use the most popular article
|
||||
send_to_user(f"_keyword: {keyword}_\n\n{news_formatted}", pUser_id=p_user_id, md_mode=True) # send news with related keyword in Markdown
|
||||
|
||||
|
||||
def send_to_user(pText, pUser_id, md_mode=False):
|
||||
""" Send message to user
|
||||
:type pText: string
|
||||
:param pText: Text to send to user
|
||||
|
||||
:type pUser_id: int
|
||||
:param pUser_id: user to send to. per default me (Florian Kellermann)
|
||||
|
||||
:type md_mode: boolean
|
||||
:param md_mode: if true, parse_mode is markdown
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
if md_mode:
|
||||
bot.send_message(chat_id=pUser_id, text=pText, parse_mode="MARKDOWNV2")
|
||||
else:
|
||||
bot.send_message(chat_id=pUser_id, text=pText)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
start_updater()
|
||||
sys.exit(-1)
|
||||
except KeyboardInterrupt:
|
||||
print("Ending")
|
||||
sys.exit(-1)</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="telegram_bot.bot_updates.send_to_user"><code class="name flex">
|
||||
<span>def <span class="ident">send_to_user</span></span>(<span>pText, pUser_id, md_mode=False)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Send message to user
|
||||
:type pText: string
|
||||
:param pText: Text to send to user</p>
|
||||
<p>:type pUser_id: int
|
||||
:param pUser_id: user to send to. per default me (Florian Kellermann)</p>
|
||||
<p>:type md_mode: boolean
|
||||
:param md_mode: if true, parse_mode is markdown</p>
|
||||
<p>:raises: none</p>
|
||||
<p>:rtype: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def send_to_user(pText, pUser_id, md_mode=False):
|
||||
""" Send message to user
|
||||
:type pText: string
|
||||
:param pText: Text to send to user
|
||||
|
||||
:type pUser_id: int
|
||||
:param pUser_id: user to send to. per default me (Florian Kellermann)
|
||||
|
||||
:type md_mode: boolean
|
||||
:param md_mode: if true, parse_mode is markdown
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
if md_mode:
|
||||
bot.send_message(chat_id=pUser_id, text=pText, parse_mode="MARKDOWNV2")
|
||||
else:
|
||||
bot.send_message(chat_id=pUser_id, text=pText)</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.bot_updates.start_updater"><code class="name flex">
|
||||
<span>def <span class="ident">start_updater</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>starting function for regularly sending updates
|
||||
:raises: none</p>
|
||||
<p>:rtype: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def start_updater():
|
||||
""" starting function for regularly sending updates
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
print("Bot updates started")
|
||||
|
||||
my_handler = API_Handler("https://gruppe1.testsites.info/api", str(os.getenv("BOT_EMAIL")), str(os.getenv("BOT_PASSWORD")))
|
||||
|
||||
update_crontab(my_handler)</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.bot_updates.update_based_on_crontab"><code class="name flex">
|
||||
<span>def <span class="ident">update_based_on_crontab</span></span>(<span>p_user_ids, p_user_crontab, p_my_handler)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Check all the crontab codes and add jobs to start in time
|
||||
:type p_user_ids: array
|
||||
:param p_user_ids: user id array of all users</p>
|
||||
<p>:type p_user_crontab: array
|
||||
:param p_user_crontab: crontabs for all users equivalent to the user array</p>
|
||||
<p>:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: get database stuff</p>
|
||||
<p>:raises: none</p>
|
||||
<p>:rtype: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def update_based_on_crontab(p_user_ids, p_user_crontab, p_my_handler):
|
||||
""" Check all the crontab codes and add jobs to start in time
|
||||
:type p_user_ids: array
|
||||
:param p_user_ids: user id array of all users
|
||||
|
||||
:type p_user_crontab: array
|
||||
:param p_user_crontab: crontabs for all users equivalent to the user array
|
||||
|
||||
:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: get database stuff
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
my_scheduler = BackgroundScheduler() # schedule sends based on cron
|
||||
|
||||
for i in range(len(p_user_ids)):
|
||||
cron_split = p_user_crontab[i].split(" ") # split it up to use in scheduler
|
||||
print(cron_split[4], cron_split[1], cron_split[0], cron_split[3], cron_split[2])
|
||||
my_scheduler.add_job(update_for_user, 'cron', day_of_week=cron_split[4], hour=cron_split[1], minute=cron_split[0], month=cron_split[3], day=cron_split[2], args=(p_user_ids[i], p_my_handler))
|
||||
|
||||
my_scheduler.start()
|
||||
|
||||
time.sleep( 600 ) # scheduler runs in background and I wait 10mins
|
||||
my_scheduler.shutdown() # after this the new crontabs will be loaded</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.bot_updates.update_crontab"><code class="name flex">
|
||||
<span>def <span class="ident">update_crontab</span></span>(<span>p_my_handler)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Updating crontab lists every hour
|
||||
:type pCurrent_Time: time when starting crontab update
|
||||
:param pCurrent_Time: datetime</p>
|
||||
<p>:raises: none</p>
|
||||
<p>:rtype: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def update_crontab(p_my_handler):
|
||||
""" Updating crontab lists every hour
|
||||
:type pCurrent_Time: time when starting crontab update
|
||||
:param pCurrent_Time: datetime
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
|
||||
global user_crontab
|
||||
global user_ids
|
||||
|
||||
all_users = p_my_handler.get_all_users() # get all users so crontabs can update for everybody
|
||||
|
||||
user_ids = []
|
||||
user_crontab = []
|
||||
|
||||
for element in all_users:
|
||||
if element["cron"] != '' and element["telegram_user_id"] != '': # check if both values are existing so I have consistent data
|
||||
try:
|
||||
user_ids.append(int(element["telegram_user_id"]))
|
||||
try:
|
||||
user_crontab.append(str(element["cron"]))
|
||||
except:
|
||||
user_ids.pop() # if something goes wrong with cron I have to delete matching user id
|
||||
except: continue
|
||||
|
||||
|
||||
print(user_ids)
|
||||
|
||||
update_based_on_crontab(user_ids, user_crontab, p_my_handler)
|
||||
|
||||
update_crontab(p_my_handler) # restart the update after time sleep</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.bot_updates.update_for_user"><code class="name flex">
|
||||
<span>def <span class="ident">update_for_user</span></span>(<span>p_user_id, p_my_handler)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Pull shares and send updates for specific user id
|
||||
:type p_user_id: integer
|
||||
:param p_user_id: user id of user that shall receive update</p>
|
||||
<p>:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: handle the api and pull from database</p>
|
||||
<p>:raises: none</p>
|
||||
<p>:rtype: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def update_for_user(p_user_id, p_my_handler):
|
||||
""" Pull shares and send updates for specific user id
|
||||
:type p_user_id: integer
|
||||
:param p_user_id: user id of user that shall receive update
|
||||
|
||||
:type p_my_handler: Api_Handler
|
||||
:param p_my_handler: handle the api and pull from database
|
||||
|
||||
:raises: none
|
||||
|
||||
:rtype: none
|
||||
"""
|
||||
share_symbols = []
|
||||
share_amounts = []
|
||||
|
||||
my_portfolio = p_my_handler.get_user_portfolio(p_user_id) # get all existing shares for user
|
||||
|
||||
for element in my_portfolio:
|
||||
if element["count"] != '' and element["isin"] != '':
|
||||
print(element["count"], element["isin"])
|
||||
share_symbols.append(element["isin"])
|
||||
share_amounts.append(element["count"])
|
||||
|
||||
my_user = p_my_handler.get_user(p_user_id)
|
||||
send_to_user("Hello %s this is your share update for today:"%str(my_user["username"]), pUser_id=p_user_id)
|
||||
|
||||
shares = p_my_handler.get_user_shares(p_user_id) # all interest shares
|
||||
|
||||
if len(share_symbols) != 0: # iterate through all shares
|
||||
for i in range(len(share_symbols)):
|
||||
my_price = share_fetcher.get_share_price_no_currency(share_symbols[i])
|
||||
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {hf.make_markdown_proof(share_amounts[i])}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
|
||||
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode="MARKDOWNV2")
|
||||
else:
|
||||
send_to_user("No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.", pUser_id=p_user_id)
|
||||
|
||||
if len(shares) != 0: # Send updates on watchlist shares if existing
|
||||
send_to_user("Your watchlist shares:", pUser_id=p_user_id)
|
||||
for element in shares:
|
||||
send_to_user(share_fetcher.get_share_information_markdown(element), pUser_id=p_user_id, md_mode=True)
|
||||
|
||||
keywords = p_my_handler.get_user_keywords(p_user_id) # get keywords as array
|
||||
|
||||
if (keywords): # if keywords exist and array is not empty
|
||||
send_to_user("If you haven't read yet: \nHere are some interesting news according to your keywords:", pUser_id=p_user_id)
|
||||
for keyword in keywords:
|
||||
news = news_fetcher.get_top_news_by_keyword(keyword)["articles"]
|
||||
keyword = hf.make_markdown_proof(keyword)
|
||||
|
||||
if not news: # if empty news array
|
||||
send_to_user(f"No news found for keyword _{keyword}_\.", pUser_id=p_user_id, md_mode=True)
|
||||
|
||||
elif news == None: # if news is none
|
||||
send_to_user(f"Server error for keyword _{keyword}_\.", pUser_id=p_user_id, md_mode=True)
|
||||
else:
|
||||
news_formatted = news_fetcher.format_article(news[0]) # format for message, only use the most popular article
|
||||
send_to_user(f"_keyword: {keyword}_\n\n{news_formatted}", pUser_id=p_user_id, md_mode=True) # send news with related keyword in Markdown</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot" href="index.html">telegram_bot</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="telegram_bot.bot_updates.send_to_user" href="#telegram_bot.bot_updates.send_to_user">send_to_user</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot_updates.start_updater" href="#telegram_bot.bot_updates.start_updater">start_updater</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot_updates.update_based_on_crontab" href="#telegram_bot.bot_updates.update_based_on_crontab">update_based_on_crontab</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot_updates.update_crontab" href="#telegram_bot.bot_updates.update_crontab">update_crontab</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot_updates.update_for_user" href="#telegram_bot.bot_updates.update_for_user">update_for_user</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
220
documentation/telegram_bot/helper_functions.html
Normal file
220
documentation/telegram_bot/helper_functions.html
Normal file
@ -0,0 +1,220 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.helper_functions API documentation</title>
|
||||
<meta name="description" content="script for helper functions for bot related stuff" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>telegram_bot.helper_functions</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>script for helper functions for bot related stuff</p>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">"""
|
||||
script for helper functions for bot related stuff
|
||||
"""
|
||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
||||
__date__ = "10.05.2022"
|
||||
__version__ = "1.0.0"
|
||||
__license__ = "None"
|
||||
|
||||
|
||||
def contains_markdownv1_symbols(text):
|
||||
""" checks if text contains markdown symbols
|
||||
:type text: string
|
||||
|
||||
:param text: text to check
|
||||
|
||||
:return: true if text contains markdown symbols
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
if text.find("_") != -1 or text.find("*") != -1 or text.find("`") != -1: # check if text contains relevant markdown symbols
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def make_markdown_proof(text): # used to avoid errors related to markdown parsemode for telegram messaging
|
||||
""" makes text markdown proof
|
||||
:type text: string
|
||||
|
||||
:param text: text to make markdown proof
|
||||
|
||||
:return: markdown proof text
|
||||
|
||||
:rtype: string
|
||||
"""
|
||||
text = str(text)
|
||||
|
||||
text = text.replace("_", "\\_") # replace _ with \_ because \ is used as escape character in markdown, double escape is needed because \ is also a escape character in strings
|
||||
text = text.replace("*", "\\*")
|
||||
text = text.replace("`", "\\`")
|
||||
text = text.replace("[", "\\[")
|
||||
text = text.replace("]", "\\]")
|
||||
text = text.replace("(", "\\(")
|
||||
text = text.replace(")", "\\)")
|
||||
text = text.replace("#", "\\#")
|
||||
text = text.replace("+", "\\+")
|
||||
text = text.replace("-", "\\-")
|
||||
text = text.replace("!", "\\!")
|
||||
text = text.replace(".", "\\.")
|
||||
text = text.replace("?", "\\?")
|
||||
text = text.replace("/", "\\/")
|
||||
text = text.replace("~", "\\~")
|
||||
text = text.replace("|", "\\|")
|
||||
text = text.replace("<", "\\<")
|
||||
text = text.replace(">", "\\>")
|
||||
text = text.replace("&", "\\&")
|
||||
text = text.replace("^", "\\^")
|
||||
text = text.replace("$", "\\$")
|
||||
text = text.replace("%", "\\%")
|
||||
text = text.replace("=", "\\=")
|
||||
text = text.replace("@", "\\@")
|
||||
|
||||
return text
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("this is a module for helper functions for the bot and should not be run directly")
|
||||
print(make_markdown_proof("_test_"))
|
||||
text = make_markdown_proof("_test_")
|
||||
print(f"{text}")</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="telegram_bot.helper_functions.contains_markdownv1_symbols"><code class="name flex">
|
||||
<span>def <span class="ident">contains_markdownv1_symbols</span></span>(<span>text)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>checks if text contains markdown symbols
|
||||
:type text: string</p>
|
||||
<p>:param text: text to check</p>
|
||||
<p>:return: true if text contains markdown symbols</p>
|
||||
<p>:rtype: bool</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def contains_markdownv1_symbols(text):
|
||||
""" checks if text contains markdown symbols
|
||||
:type text: string
|
||||
|
||||
:param text: text to check
|
||||
|
||||
:return: true if text contains markdown symbols
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
if text.find("_") != -1 or text.find("*") != -1 or text.find("`") != -1: # check if text contains relevant markdown symbols
|
||||
return True
|
||||
|
||||
return False</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.helper_functions.make_markdown_proof"><code class="name flex">
|
||||
<span>def <span class="ident">make_markdown_proof</span></span>(<span>text)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>makes text markdown proof
|
||||
:type text: string</p>
|
||||
<p>:param text: text to make markdown proof</p>
|
||||
<p>:return: markdown proof text</p>
|
||||
<p>:rtype: string</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def make_markdown_proof(text): # used to avoid errors related to markdown parsemode for telegram messaging
|
||||
""" makes text markdown proof
|
||||
:type text: string
|
||||
|
||||
:param text: text to make markdown proof
|
||||
|
||||
:return: markdown proof text
|
||||
|
||||
:rtype: string
|
||||
"""
|
||||
text = str(text)
|
||||
|
||||
text = text.replace("_", "\\_") # replace _ with \_ because \ is used as escape character in markdown, double escape is needed because \ is also a escape character in strings
|
||||
text = text.replace("*", "\\*")
|
||||
text = text.replace("`", "\\`")
|
||||
text = text.replace("[", "\\[")
|
||||
text = text.replace("]", "\\]")
|
||||
text = text.replace("(", "\\(")
|
||||
text = text.replace(")", "\\)")
|
||||
text = text.replace("#", "\\#")
|
||||
text = text.replace("+", "\\+")
|
||||
text = text.replace("-", "\\-")
|
||||
text = text.replace("!", "\\!")
|
||||
text = text.replace(".", "\\.")
|
||||
text = text.replace("?", "\\?")
|
||||
text = text.replace("/", "\\/")
|
||||
text = text.replace("~", "\\~")
|
||||
text = text.replace("|", "\\|")
|
||||
text = text.replace("<", "\\<")
|
||||
text = text.replace(">", "\\>")
|
||||
text = text.replace("&", "\\&")
|
||||
text = text.replace("^", "\\^")
|
||||
text = text.replace("$", "\\$")
|
||||
text = text.replace("%", "\\%")
|
||||
text = text.replace("=", "\\=")
|
||||
text = text.replace("@", "\\@")
|
||||
|
||||
return text</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot" href="index.html">telegram_bot</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="telegram_bot.helper_functions.contains_markdownv1_symbols" href="#telegram_bot.helper_functions.contains_markdownv1_symbols">contains_markdownv1_symbols</a></code></li>
|
||||
<li><code><a title="telegram_bot.helper_functions.make_markdown_proof" href="#telegram_bot.helper_functions.make_markdown_proof">make_markdown_proof</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
85
documentation/telegram_bot/index.html
Normal file
85
documentation/telegram_bot/index.html
Normal file
@ -0,0 +1,85 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot API documentation</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Namespace <code>telegram_bot</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-submodules">Sub-modules</h2>
|
||||
<dl>
|
||||
<dt><code class="name"><a title="telegram_bot.api_handling" href="api_handling/index.html">telegram_bot.api_handling</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="telegram_bot.bot" href="bot.html">telegram_bot.bot</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for telegram bot and its functions</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="telegram_bot.bot_updates" href="bot_updates.html">telegram_bot.bot_updates</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for regularly sending updates on shares and news based on user interval</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="telegram_bot.helper_functions" href="helper_functions.html">telegram_bot.helper_functions</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for helper functions for bot related stuff</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="telegram_bot.news" href="news/index.html">telegram_bot.news</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="telegram_bot.shares" href="shares/index.html">telegram_bot.shares</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3><a href="#header-submodules">Sub-modules</a></h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.api_handling" href="api_handling/index.html">telegram_bot.api_handling</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot" href="bot.html">telegram_bot.bot</a></code></li>
|
||||
<li><code><a title="telegram_bot.bot_updates" href="bot_updates.html">telegram_bot.bot_updates</a></code></li>
|
||||
<li><code><a title="telegram_bot.helper_functions" href="helper_functions.html">telegram_bot.helper_functions</a></code></li>
|
||||
<li><code><a title="telegram_bot.news" href="news/index.html">telegram_bot.news</a></code></li>
|
||||
<li><code><a title="telegram_bot.shares" href="shares/index.html">telegram_bot.shares</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
65
documentation/telegram_bot/news/index.html
Normal file
65
documentation/telegram_bot/news/index.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.news API documentation</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Namespace <code>telegram_bot.news</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-submodules">Sub-modules</h2>
|
||||
<dl>
|
||||
<dt><code class="name"><a title="telegram_bot.news.news_fetcher" href="news_fetcher.html">telegram_bot.news.news_fetcher</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for news fetching (by keywords)</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot" href="../index.html">telegram_bot</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-submodules">Sub-modules</a></h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.news.news_fetcher" href="news_fetcher.html">telegram_bot.news.news_fetcher</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
264
documentation/telegram_bot/news/news_fetcher.html
Normal file
264
documentation/telegram_bot/news/news_fetcher.html
Normal file
@ -0,0 +1,264 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.news.news_fetcher API documentation</title>
|
||||
<meta name="description" content="script for news fetching (by keywords)" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>telegram_bot.news.news_fetcher</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>script for news fetching (by keywords)</p>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">"""
|
||||
script for news fetching (by keywords)
|
||||
"""
|
||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
||||
__date__ = "26.04.2022"
|
||||
__version__ = "1.0.0"
|
||||
__license__ = "None"
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import telegram_bot.helper_functions as hf
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
from newsapi import NewsApiClient
|
||||
|
||||
load_dotenv() # loads environment vars
|
||||
|
||||
# Init
|
||||
api_key = os.getenv('NEWS_API_KEY') # get API Key from .env file
|
||||
newsapi = NewsApiClient(api_key=api_key) # news api from https://newsapi.org/
|
||||
|
||||
try:
|
||||
# get all available news sources (e.g BBC, New York Times, etc.)
|
||||
source_json = requests.get(f"https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&language=en").json()
|
||||
sources = source_json["sources"]
|
||||
str_sources = ",".join([source["id"] for source in sources])
|
||||
|
||||
except KeyError:
|
||||
print("Error: Could not get sources, may be blocked because of too many requests (free newsapi is limited to 100 reqs per day)")
|
||||
str_sources = str(
|
||||
"Reuters, bbc, cnn, fox-news, google-news, hacker-news, nytimes, the-huffington-post, the-new-york-times, business-insider, bbc-news, cbc-news, ESPN, fox-sports, google-news-uk, independent, the-wall-street-journal, the-washington-times, time, usa-today")
|
||||
|
||||
|
||||
def get_all_news_by_keyword(keyword, from_date="2000-01-01"):
|
||||
"""get all news to keyword
|
||||
Args:
|
||||
keyword (String): keyword for search
|
||||
from_date (String): min date for search
|
||||
|
||||
Returns:
|
||||
JSON/dict: dict containing articles
|
||||
"""
|
||||
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) # keywords can be combined with OR (e.g. keyword = "bitcoin OR ethereum")
|
||||
if (top_headlines["status"] == "ok"):
|
||||
return top_headlines
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_top_news_by_keyword(keyword):
|
||||
"""get top news to keyword
|
||||
Args:
|
||||
keyword (String): keyword for search
|
||||
|
||||
Returns:
|
||||
JSON/dict: dict containing articles
|
||||
"""
|
||||
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en') # get top headlines, measured by popularity from NewsApi
|
||||
if (top_headlines["status"] == "ok"):
|
||||
return top_headlines
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def format_article(article):
|
||||
"""format article for messaging (using markdown syntax)
|
||||
|
||||
Args:
|
||||
article (dict): article to format for messaging
|
||||
|
||||
Returns:
|
||||
String: formatted article
|
||||
"""
|
||||
sourcename = hf.make_markdown_proof(article["source"]["name"]) # make attributes markdownv2 proof
|
||||
headline = hf.make_markdown_proof(article["title"])
|
||||
url = hf.make_markdown_proof(article["url"])
|
||||
formatted_article = f"_{sourcename}_\n*{headline}*\n\n{url}" # formatting in Markdown syntax
|
||||
|
||||
return formatted_article
|
||||
|
||||
|
||||
if __name__ == '__main__': # only execute if script is called directly -> for simple testing
|
||||
|
||||
print("this is a module and should not be run directly")
|
||||
print("fetching top news by keyword bitcoin...")
|
||||
|
||||
articles = get_all_news_by_keyword("bitcoin")
|
||||
formatted_article = format_article(articles["articles"][0])
|
||||
print(formatted_article)
|
||||
articles = get_top_news_by_keyword("bitcoin")
|
||||
formatted_article = format_article(articles["articles"][0])
|
||||
print(formatted_article)
|
||||
sys.exit(1)</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="telegram_bot.news.news_fetcher.format_article"><code class="name flex">
|
||||
<span>def <span class="ident">format_article</span></span>(<span>article)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>format article for messaging (using markdown syntax)</p>
|
||||
<h2 id="args">Args</h2>
|
||||
<dl>
|
||||
<dt><strong><code>article</code></strong> : <code>dict</code></dt>
|
||||
<dd>article to format for messaging</dd>
|
||||
</dl>
|
||||
<h2 id="returns">Returns</h2>
|
||||
<dl>
|
||||
<dt><code>String</code></dt>
|
||||
<dd>formatted article</dd>
|
||||
</dl></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def format_article(article):
|
||||
"""format article for messaging (using markdown syntax)
|
||||
|
||||
Args:
|
||||
article (dict): article to format for messaging
|
||||
|
||||
Returns:
|
||||
String: formatted article
|
||||
"""
|
||||
sourcename = hf.make_markdown_proof(article["source"]["name"]) # make attributes markdownv2 proof
|
||||
headline = hf.make_markdown_proof(article["title"])
|
||||
url = hf.make_markdown_proof(article["url"])
|
||||
formatted_article = f"_{sourcename}_\n*{headline}*\n\n{url}" # formatting in Markdown syntax
|
||||
|
||||
return formatted_article</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.news.news_fetcher.get_all_news_by_keyword"><code class="name flex">
|
||||
<span>def <span class="ident">get_all_news_by_keyword</span></span>(<span>keyword, from_date='2000-01-01')</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>get all news to keyword</p>
|
||||
<h2 id="args">Args</h2>
|
||||
<dl>
|
||||
<dt><strong><code>keyword</code></strong> : <code>String</code></dt>
|
||||
<dd>keyword for search</dd>
|
||||
<dt><strong><code>from_date</code></strong> : <code>String</code></dt>
|
||||
<dd>min date for search</dd>
|
||||
</dl>
|
||||
<h2 id="returns">Returns</h2>
|
||||
<p>JSON/dict: dict containing articles</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_all_news_by_keyword(keyword, from_date="2000-01-01"):
|
||||
"""get all news to keyword
|
||||
Args:
|
||||
keyword (String): keyword for search
|
||||
from_date (String): min date for search
|
||||
|
||||
Returns:
|
||||
JSON/dict: dict containing articles
|
||||
"""
|
||||
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language='en', from_param=from_date) # keywords can be combined with OR (e.g. keyword = "bitcoin OR ethereum")
|
||||
if (top_headlines["status"] == "ok"):
|
||||
return top_headlines
|
||||
else:
|
||||
return None</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.news.news_fetcher.get_top_news_by_keyword"><code class="name flex">
|
||||
<span>def <span class="ident">get_top_news_by_keyword</span></span>(<span>keyword)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>get top news to keyword</p>
|
||||
<h2 id="args">Args</h2>
|
||||
<dl>
|
||||
<dt><strong><code>keyword</code></strong> : <code>String</code></dt>
|
||||
<dd>keyword for search</dd>
|
||||
</dl>
|
||||
<h2 id="returns">Returns</h2>
|
||||
<p>JSON/dict: dict containing articles</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_top_news_by_keyword(keyword):
|
||||
"""get top news to keyword
|
||||
Args:
|
||||
keyword (String): keyword for search
|
||||
|
||||
Returns:
|
||||
JSON/dict: dict containing articles
|
||||
"""
|
||||
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language='en') # get top headlines, measured by popularity from NewsApi
|
||||
if (top_headlines["status"] == "ok"):
|
||||
return top_headlines
|
||||
else:
|
||||
return None</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.news" href="index.html">telegram_bot.news</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="telegram_bot.news.news_fetcher.format_article" href="#telegram_bot.news.news_fetcher.format_article">format_article</a></code></li>
|
||||
<li><code><a title="telegram_bot.news.news_fetcher.get_all_news_by_keyword" href="#telegram_bot.news.news_fetcher.get_all_news_by_keyword">get_all_news_by_keyword</a></code></li>
|
||||
<li><code><a title="telegram_bot.news.news_fetcher.get_top_news_by_keyword" href="#telegram_bot.news.news_fetcher.get_top_news_by_keyword">get_top_news_by_keyword</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
65
documentation/telegram_bot/shares/index.html
Normal file
65
documentation/telegram_bot/shares/index.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.shares API documentation</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Namespace <code>telegram_bot.shares</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-submodules">Sub-modules</h2>
|
||||
<dl>
|
||||
<dt><code class="name"><a title="telegram_bot.shares.share_fetcher" href="share_fetcher.html">telegram_bot.shares.share_fetcher</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>script for share fetching (by symbols (e.g. AAPL, TSLA etc.))</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot" href="../index.html">telegram_bot</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-submodules">Sub-modules</a></h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher" href="share_fetcher.html">telegram_bot.shares.share_fetcher</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
384
documentation/telegram_bot/shares/share_fetcher.html
Normal file
384
documentation/telegram_bot/shares/share_fetcher.html
Normal file
@ -0,0 +1,384 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
|
||||
<meta name="generator" content="pdoc 0.10.0" />
|
||||
<title>telegram_bot.shares.share_fetcher API documentation</title>
|
||||
<meta name="description" content="script for share fetching (by symbols (e.g. AAPL, TSLA etc.))" />
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
|
||||
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
|
||||
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>telegram_bot.shares.share_fetcher</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>script for share fetching (by symbols (e.g. AAPL, TSLA etc.))</p>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">"""
|
||||
script for share fetching (by symbols (e.g. AAPL, TSLA etc.))
|
||||
"""
|
||||
__author__ = "Florian Kellermann, Linus Eickhoff"
|
||||
__date__ = "10.05.2022"
|
||||
__version__ = "1.0.1"
|
||||
__license__ = "None"
|
||||
|
||||
import telegram_bot.helper_functions as hf
|
||||
import investpy
|
||||
import pandas
|
||||
from currency_converter import CurrencyConverter
|
||||
|
||||
|
||||
def get_share_price(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol
|
||||
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany'])
|
||||
|
||||
currency = str(search_result.retrieve_currency()) # retrieve currency from data
|
||||
# should always be Euro because of countries=['germany']
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"] # retrieve latest stock price
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return =str(stock_price) + " " + str(currency) # return + currency
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError: # if no shares are found for germany (e.g. isin: US.....)
|
||||
try:
|
||||
my_Converter = CurrencyConverter() # need a currency converter
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
#convert stock price from currency to EUR
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return = str(stock_price) + " EUR"
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError:
|
||||
return "None"
|
||||
|
||||
|
||||
def get_share_price_no_currency(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol no currency
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
return stock_price
|
||||
|
||||
except RuntimeError:
|
||||
my_Converter = CurrencyConverter()
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return = str(stock_price)
|
||||
|
||||
return str_return
|
||||
|
||||
|
||||
def get_share_information(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
|
||||
|
||||
return str_return
|
||||
|
||||
|
||||
def get_share_information_markdown(str_search_for):
|
||||
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
except RuntimeError as e:
|
||||
return hf.make_markdown_proof(f"no shares found for \"{str_search_for}\"") # if no shares are found, make error message markdown proof and return
|
||||
|
||||
except ConnectionError as e:
|
||||
return hf.make_markdown_proof(f"connection not possible. Try again later.") # if no connection, make error message markdown proof and return
|
||||
|
||||
str_return = f'*{hf.make_markdown_proof(search_result.name)}*\n_{hf.make_markdown_proof(search_result.symbol)}_\nworth: {hf.make_markdown_proof(get_share_price(str_search_for))}'
|
||||
return str_return
|
||||
|
||||
|
||||
def get_share_information_simple(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = search_result.name + "\n" + search_result.symbol + "\nworth: " + get_share_price(str_search_for)
|
||||
return str_return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("None")</code></pre>
|
||||
</details>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="telegram_bot.shares.share_fetcher.get_share_information"><code class="name flex">
|
||||
<span>def <span class="ident">get_share_information</span></span>(<span>str_search_for)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_share_information(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
|
||||
|
||||
return str_return</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.shares.share_fetcher.get_share_information_markdown"><code class="name flex">
|
||||
<span>def <span class="ident">get_share_information_markdown</span></span>(<span>str_search_for)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_share_information_markdown(str_search_for):
|
||||
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
except RuntimeError as e:
|
||||
return hf.make_markdown_proof(f"no shares found for \"{str_search_for}\"") # if no shares are found, make error message markdown proof and return
|
||||
|
||||
except ConnectionError as e:
|
||||
return hf.make_markdown_proof(f"connection not possible. Try again later.") # if no connection, make error message markdown proof and return
|
||||
|
||||
str_return = f'*{hf.make_markdown_proof(search_result.name)}*\n_{hf.make_markdown_proof(search_result.symbol)}_\nworth: {hf.make_markdown_proof(get_share_price(str_search_for))}'
|
||||
return str_return</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.shares.share_fetcher.get_share_information_simple"><code class="name flex">
|
||||
<span>def <span class="ident">get_share_information_simple</span></span>(<span>str_search_for)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_share_information_simple(str_search_for):
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
str_return = search_result.name + "\n" + search_result.symbol + "\nworth: " + get_share_price(str_search_for)
|
||||
return str_return</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.shares.share_fetcher.get_share_price"><code class="name flex">
|
||||
<span>def <span class="ident">get_share_price</span></span>(<span>str_search_for)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>get stock price per share for company name or isin or symbol</p>
|
||||
<h2 id="args">Args</h2>
|
||||
<dl>
|
||||
<dt><strong><code>str_search_for</code></strong> : <code>string</code></dt>
|
||||
<dd>search for this string/isin</dd>
|
||||
</dl>
|
||||
<p>Returns: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_share_price(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol
|
||||
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany'])
|
||||
|
||||
currency = str(search_result.retrieve_currency()) # retrieve currency from data
|
||||
# should always be Euro because of countries=['germany']
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"] # retrieve latest stock price
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return =str(stock_price) + " " + str(currency) # return + currency
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError: # if no shares are found for germany (e.g. isin: US.....)
|
||||
try:
|
||||
my_Converter = CurrencyConverter() # need a currency converter
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
#convert stock price from currency to EUR
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return = str(stock_price) + " EUR"
|
||||
|
||||
return str_return
|
||||
|
||||
except RuntimeError:
|
||||
return "None"</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="telegram_bot.shares.share_fetcher.get_share_price_no_currency"><code class="name flex">
|
||||
<span>def <span class="ident">get_share_price_no_currency</span></span>(<span>str_search_for)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>get stock price per share for company name or isin or symbol no currency</p>
|
||||
<h2 id="args">Args</h2>
|
||||
<dl>
|
||||
<dt><strong><code>str_search_for</code></strong> : <code>string</code></dt>
|
||||
<dd>search for this string/isin</dd>
|
||||
</dl>
|
||||
<p>Returns: none</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def get_share_price_no_currency(str_search_for):
|
||||
"""get stock price per share for company name or isin or symbol no currency
|
||||
Args:
|
||||
str_search_for (string): search for this string/isin
|
||||
Returns: none
|
||||
"""
|
||||
try:
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
|
||||
countries=['germany'], n_results=1)
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
return stock_price
|
||||
|
||||
except RuntimeError:
|
||||
my_Converter = CurrencyConverter()
|
||||
|
||||
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1)
|
||||
|
||||
currency = str(search_result.retrieve_currency())
|
||||
|
||||
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
|
||||
|
||||
stock_price = recent_data.iloc[-1]["Close"]
|
||||
|
||||
stock_price = my_Converter.convert(float(stock_price), str(currency), 'EUR')
|
||||
|
||||
stock_price = round(float(stock_price), 2)
|
||||
|
||||
str_return = str(stock_price)
|
||||
|
||||
return str_return</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<h1>Index</h1>
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="telegram_bot.shares" href="index.html">telegram_bot.shares</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher.get_share_information" href="#telegram_bot.shares.share_fetcher.get_share_information">get_share_information</a></code></li>
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher.get_share_information_markdown" href="#telegram_bot.shares.share_fetcher.get_share_information_markdown">get_share_information_markdown</a></code></li>
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher.get_share_information_simple" href="#telegram_bot.shares.share_fetcher.get_share_information_simple">get_share_information_simple</a></code></li>
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher.get_share_price" href="#telegram_bot.shares.share_fetcher.get_share_price">get_share_price</a></code></li>
|
||||
<li><code><a title="telegram_bot.shares.share_fetcher.get_share_price_no_currency" href="#telegram_bot.shares.share_fetcher.get_share_price_no_currency">get_share_price_no_currency</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user