Bot #186

Merged
Rripped merged 3 commits from bot into main 2022-05-12 14:37:14 +00:00
11 changed files with 5039 additions and 2 deletions

File diff suppressed because it is too large Load Diff

View 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>

File diff suppressed because it is too large Load Diff

View 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">&#34;&#34;&#34;
script for regularly sending updates on shares and news based on user interval
&#34;&#34;&#34;
__author__ = &#34;Florian Kellermann, Linus Eickhoff&#34;
__date__ = &#34;10.05.2022&#34;
__version__ = &#34;1.0.2&#34;
__license__ = &#34;None&#34;
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
&#39;&#39;&#39;
* * * * * code
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── weekday (0-&gt;Monday, 7-&gt;Sunday)
│ │ │ └────── Month (1-12)
│ │ └──────── Day (1-31)
│ └────────── Hour (0-23)
└──────────── Minute (0-59)
example 0 8 * * * -&gt; daily update at 8am
&#39;&#39;&#39;
user_ids = []
user_crontab = []
load_dotenv(dotenv_path=&#39;.env&#39;)
def start_updater():
&#34;&#34;&#34; starting function for regularly sending updates
:raises: none
:rtype: none
&#34;&#34;&#34;
print(&#34;Bot updates started&#34;)
my_handler = API_Handler(&#34;https://gruppe1.testsites.info/api&#34;, str(os.getenv(&#34;BOT_EMAIL&#34;)), str(os.getenv(&#34;BOT_PASSWORD&#34;)))
update_crontab(my_handler)
def update_crontab(p_my_handler):
&#34;&#34;&#34; Updating crontab lists every hour
:type pCurrent_Time: time when starting crontab update
:param pCurrent_Time: datetime
:raises: none
:rtype: none
&#34;&#34;&#34;
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[&#34;cron&#34;] != &#39;&#39; and element[&#34;telegram_user_id&#34;] != &#39;&#39;: # check if both values are existing so I have consistent data
try:
user_ids.append(int(element[&#34;telegram_user_id&#34;]))
try:
user_crontab.append(str(element[&#34;cron&#34;]))
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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
my_scheduler = BackgroundScheduler() # schedule sends based on cron
for i in range(len(p_user_ids)):
cron_split = p_user_crontab[i].split(&#34; &#34;) # 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, &#39;cron&#39;, 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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
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[&#34;count&#34;] != &#39;&#39; and element[&#34;isin&#34;] != &#39;&#39;:
print(element[&#34;count&#34;], element[&#34;isin&#34;])
share_symbols.append(element[&#34;isin&#34;])
share_amounts.append(element[&#34;count&#34;])
my_user = p_my_handler.get_user(p_user_id)
send_to_user(&#34;Hello %s this is your share update for today:&#34;%str(my_user[&#34;username&#34;]), 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&#39;{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&#39;
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode=&#34;MARKDOWNV2&#34;)
else:
send_to_user(&#34;No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.&#34;, pUser_id=p_user_id)
if len(shares) != 0: # Send updates on watchlist shares if existing
send_to_user(&#34;Your watchlist shares:&#34;, 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(&#34;If you haven&#39;t read yet: \nHere are some interesting news according to your keywords:&#34;, pUser_id=p_user_id)
for keyword in keywords:
news = news_fetcher.get_top_news_by_keyword(keyword)[&#34;articles&#34;]
keyword = hf.make_markdown_proof(keyword)
if not news: # if empty news array
send_to_user(f&#34;No news found for keyword _{keyword}_\.&#34;, pUser_id=p_user_id, md_mode=True)
elif news == None: # if news is none
send_to_user(f&#34;Server error for keyword _{keyword}_\.&#34;, 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&#34;_keyword: {keyword}_\n\n{news_formatted}&#34;, 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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
if md_mode:
bot.send_message(chat_id=pUser_id, text=pText, parse_mode=&#34;MARKDOWNV2&#34;)
else:
bot.send_message(chat_id=pUser_id, text=pText)
if __name__ == &#34;__main__&#34;:
try:
start_updater()
sys.exit(-1)
except KeyboardInterrupt:
print(&#34;Ending&#34;)
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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
if md_mode:
bot.send_message(chat_id=pUser_id, text=pText, parse_mode=&#34;MARKDOWNV2&#34;)
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():
&#34;&#34;&#34; starting function for regularly sending updates
:raises: none
:rtype: none
&#34;&#34;&#34;
print(&#34;Bot updates started&#34;)
my_handler = API_Handler(&#34;https://gruppe1.testsites.info/api&#34;, str(os.getenv(&#34;BOT_EMAIL&#34;)), str(os.getenv(&#34;BOT_PASSWORD&#34;)))
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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
my_scheduler = BackgroundScheduler() # schedule sends based on cron
for i in range(len(p_user_ids)):
cron_split = p_user_crontab[i].split(&#34; &#34;) # 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, &#39;cron&#39;, 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):
&#34;&#34;&#34; Updating crontab lists every hour
:type pCurrent_Time: time when starting crontab update
:param pCurrent_Time: datetime
:raises: none
:rtype: none
&#34;&#34;&#34;
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[&#34;cron&#34;] != &#39;&#39; and element[&#34;telegram_user_id&#34;] != &#39;&#39;: # check if both values are existing so I have consistent data
try:
user_ids.append(int(element[&#34;telegram_user_id&#34;]))
try:
user_crontab.append(str(element[&#34;cron&#34;]))
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):
&#34;&#34;&#34; 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
&#34;&#34;&#34;
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[&#34;count&#34;] != &#39;&#39; and element[&#34;isin&#34;] != &#39;&#39;:
print(element[&#34;count&#34;], element[&#34;isin&#34;])
share_symbols.append(element[&#34;isin&#34;])
share_amounts.append(element[&#34;count&#34;])
my_user = p_my_handler.get_user(p_user_id)
send_to_user(&#34;Hello %s this is your share update for today:&#34;%str(my_user[&#34;username&#34;]), 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&#39;{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&#39;
bot.send_message(chat_id=p_user_id, text=my_update_message, parse_mode=&#34;MARKDOWNV2&#34;)
else:
send_to_user(&#34;No shares found for your account. Check https://gruppe1.testsites.info to change your settings and add shares.&#34;, pUser_id=p_user_id)
if len(shares) != 0: # Send updates on watchlist shares if existing
send_to_user(&#34;Your watchlist shares:&#34;, 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(&#34;If you haven&#39;t read yet: \nHere are some interesting news according to your keywords:&#34;, pUser_id=p_user_id)
for keyword in keywords:
news = news_fetcher.get_top_news_by_keyword(keyword)[&#34;articles&#34;]
keyword = hf.make_markdown_proof(keyword)
if not news: # if empty news array
send_to_user(f&#34;No news found for keyword _{keyword}_\.&#34;, pUser_id=p_user_id, md_mode=True)
elif news == None: # if news is none
send_to_user(f&#34;Server error for keyword _{keyword}_\.&#34;, 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&#34;_keyword: {keyword}_\n\n{news_formatted}&#34;, 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>

View 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">&#34;&#34;&#34;
script for helper functions for bot related stuff
&#34;&#34;&#34;
__author__ = &#34;Florian Kellermann, Linus Eickhoff&#34;
__date__ = &#34;10.05.2022&#34;
__version__ = &#34;1.0.0&#34;
__license__ = &#34;None&#34;
def contains_markdownv1_symbols(text):
&#34;&#34;&#34; checks if text contains markdown symbols
:type text: string
:param text: text to check
:return: true if text contains markdown symbols
:rtype: bool
&#34;&#34;&#34;
if text.find(&#34;_&#34;) != -1 or text.find(&#34;*&#34;) != -1 or text.find(&#34;`&#34;) != -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
&#34;&#34;&#34; makes text markdown proof
:type text: string
:param text: text to make markdown proof
:return: markdown proof text
:rtype: string
&#34;&#34;&#34;
text = str(text)
text = text.replace(&#34;_&#34;, &#34;\\_&#34;) # 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(&#34;*&#34;, &#34;\\*&#34;)
text = text.replace(&#34;`&#34;, &#34;\\`&#34;)
text = text.replace(&#34;[&#34;, &#34;\\[&#34;)
text = text.replace(&#34;]&#34;, &#34;\\]&#34;)
text = text.replace(&#34;(&#34;, &#34;\\(&#34;)
text = text.replace(&#34;)&#34;, &#34;\\)&#34;)
text = text.replace(&#34;#&#34;, &#34;\\#&#34;)
text = text.replace(&#34;+&#34;, &#34;\\+&#34;)
text = text.replace(&#34;-&#34;, &#34;\\-&#34;)
text = text.replace(&#34;!&#34;, &#34;\\!&#34;)
text = text.replace(&#34;.&#34;, &#34;\\.&#34;)
text = text.replace(&#34;?&#34;, &#34;\\?&#34;)
text = text.replace(&#34;/&#34;, &#34;\\/&#34;)
text = text.replace(&#34;~&#34;, &#34;\\~&#34;)
text = text.replace(&#34;|&#34;, &#34;\\|&#34;)
text = text.replace(&#34;&lt;&#34;, &#34;\\&lt;&#34;)
text = text.replace(&#34;&gt;&#34;, &#34;\\&gt;&#34;)
text = text.replace(&#34;&amp;&#34;, &#34;\\&amp;&#34;)
text = text.replace(&#34;^&#34;, &#34;\\^&#34;)
text = text.replace(&#34;$&#34;, &#34;\\$&#34;)
text = text.replace(&#34;%&#34;, &#34;\\%&#34;)
text = text.replace(&#34;=&#34;, &#34;\\=&#34;)
text = text.replace(&#34;@&#34;, &#34;\\@&#34;)
return text
if __name__ == &#39;__main__&#39;:
print(&#34;this is a module for helper functions for the bot and should not be run directly&#34;)
print(make_markdown_proof(&#34;_test_&#34;))
text = make_markdown_proof(&#34;_test_&#34;)
print(f&#34;{text}&#34;)</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):
&#34;&#34;&#34; checks if text contains markdown symbols
:type text: string
:param text: text to check
:return: true if text contains markdown symbols
:rtype: bool
&#34;&#34;&#34;
if text.find(&#34;_&#34;) != -1 or text.find(&#34;*&#34;) != -1 or text.find(&#34;`&#34;) != -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
&#34;&#34;&#34; makes text markdown proof
:type text: string
:param text: text to make markdown proof
:return: markdown proof text
:rtype: string
&#34;&#34;&#34;
text = str(text)
text = text.replace(&#34;_&#34;, &#34;\\_&#34;) # 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(&#34;*&#34;, &#34;\\*&#34;)
text = text.replace(&#34;`&#34;, &#34;\\`&#34;)
text = text.replace(&#34;[&#34;, &#34;\\[&#34;)
text = text.replace(&#34;]&#34;, &#34;\\]&#34;)
text = text.replace(&#34;(&#34;, &#34;\\(&#34;)
text = text.replace(&#34;)&#34;, &#34;\\)&#34;)
text = text.replace(&#34;#&#34;, &#34;\\#&#34;)
text = text.replace(&#34;+&#34;, &#34;\\+&#34;)
text = text.replace(&#34;-&#34;, &#34;\\-&#34;)
text = text.replace(&#34;!&#34;, &#34;\\!&#34;)
text = text.replace(&#34;.&#34;, &#34;\\.&#34;)
text = text.replace(&#34;?&#34;, &#34;\\?&#34;)
text = text.replace(&#34;/&#34;, &#34;\\/&#34;)
text = text.replace(&#34;~&#34;, &#34;\\~&#34;)
text = text.replace(&#34;|&#34;, &#34;\\|&#34;)
text = text.replace(&#34;&lt;&#34;, &#34;\\&lt;&#34;)
text = text.replace(&#34;&gt;&#34;, &#34;\\&gt;&#34;)
text = text.replace(&#34;&amp;&#34;, &#34;\\&amp;&#34;)
text = text.replace(&#34;^&#34;, &#34;\\^&#34;)
text = text.replace(&#34;$&#34;, &#34;\\$&#34;)
text = text.replace(&#34;%&#34;, &#34;\\%&#34;)
text = text.replace(&#34;=&#34;, &#34;\\=&#34;)
text = text.replace(&#34;@&#34;, &#34;\\@&#34;)
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>

View 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>

View 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>

View 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">&#34;&#34;&#34;
script for news fetching (by keywords)
&#34;&#34;&#34;
__author__ = &#34;Florian Kellermann, Linus Eickhoff&#34;
__date__ = &#34;26.04.2022&#34;
__version__ = &#34;1.0.0&#34;
__license__ = &#34;None&#34;
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(&#39;NEWS_API_KEY&#39;) # 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&#34;https://newsapi.org/v2/top-headlines/sources?apiKey={api_key}&amp;language=en&#34;).json()
sources = source_json[&#34;sources&#34;]
str_sources = &#34;,&#34;.join([source[&#34;id&#34;] for source in sources])
except KeyError:
print(&#34;Error: Could not get sources, may be blocked because of too many requests (free newsapi is limited to 100 reqs per day)&#34;)
str_sources = str(
&#34;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&#34;)
def get_all_news_by_keyword(keyword, from_date=&#34;2000-01-01&#34;):
&#34;&#34;&#34;get all news to keyword
Args:
keyword (String): keyword for search
from_date (String): min date for search
Returns:
JSON/dict: dict containing articles
&#34;&#34;&#34;
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language=&#39;en&#39;, from_param=from_date) # keywords can be combined with OR (e.g. keyword = &#34;bitcoin OR ethereum&#34;)
if (top_headlines[&#34;status&#34;] == &#34;ok&#34;):
return top_headlines
else:
return None
def get_top_news_by_keyword(keyword):
&#34;&#34;&#34;get top news to keyword
Args:
keyword (String): keyword for search
Returns:
JSON/dict: dict containing articles
&#34;&#34;&#34;
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language=&#39;en&#39;) # get top headlines, measured by popularity from NewsApi
if (top_headlines[&#34;status&#34;] == &#34;ok&#34;):
return top_headlines
else:
return None
def format_article(article):
&#34;&#34;&#34;format article for messaging (using markdown syntax)
Args:
article (dict): article to format for messaging
Returns:
String: formatted article
&#34;&#34;&#34;
sourcename = hf.make_markdown_proof(article[&#34;source&#34;][&#34;name&#34;]) # make attributes markdownv2 proof
headline = hf.make_markdown_proof(article[&#34;title&#34;])
url = hf.make_markdown_proof(article[&#34;url&#34;])
formatted_article = f&#34;_{sourcename}_\n*{headline}*\n\n{url}&#34; # formatting in Markdown syntax
return formatted_article
if __name__ == &#39;__main__&#39;: # only execute if script is called directly -&gt; for simple testing
print(&#34;this is a module and should not be run directly&#34;)
print(&#34;fetching top news by keyword bitcoin...&#34;)
articles = get_all_news_by_keyword(&#34;bitcoin&#34;)
formatted_article = format_article(articles[&#34;articles&#34;][0])
print(formatted_article)
articles = get_top_news_by_keyword(&#34;bitcoin&#34;)
formatted_article = format_article(articles[&#34;articles&#34;][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> :&ensp;<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):
&#34;&#34;&#34;format article for messaging (using markdown syntax)
Args:
article (dict): article to format for messaging
Returns:
String: formatted article
&#34;&#34;&#34;
sourcename = hf.make_markdown_proof(article[&#34;source&#34;][&#34;name&#34;]) # make attributes markdownv2 proof
headline = hf.make_markdown_proof(article[&#34;title&#34;])
url = hf.make_markdown_proof(article[&#34;url&#34;])
formatted_article = f&#34;_{sourcename}_\n*{headline}*\n\n{url}&#34; # 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> :&ensp;<code>String</code></dt>
<dd>keyword for search</dd>
<dt><strong><code>from_date</code></strong> :&ensp;<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=&#34;2000-01-01&#34;):
&#34;&#34;&#34;get all news to keyword
Args:
keyword (String): keyword for search
from_date (String): min date for search
Returns:
JSON/dict: dict containing articles
&#34;&#34;&#34;
top_headlines = newsapi.get_everything(q=keyword, sources=str_sources, language=&#39;en&#39;, from_param=from_date) # keywords can be combined with OR (e.g. keyword = &#34;bitcoin OR ethereum&#34;)
if (top_headlines[&#34;status&#34;] == &#34;ok&#34;):
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> :&ensp;<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):
&#34;&#34;&#34;get top news to keyword
Args:
keyword (String): keyword for search
Returns:
JSON/dict: dict containing articles
&#34;&#34;&#34;
top_headlines = newsapi.get_top_headlines(q=keyword, sources=str_sources, language=&#39;en&#39;) # get top headlines, measured by popularity from NewsApi
if (top_headlines[&#34;status&#34;] == &#34;ok&#34;):
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>

View 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>

View 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">&#34;&#34;&#34;
script for share fetching (by symbols (e.g. AAPL, TSLA etc.))
&#34;&#34;&#34;
__author__ = &#34;Florian Kellermann, Linus Eickhoff&#34;
__date__ = &#34;10.05.2022&#34;
__version__ = &#34;1.0.1&#34;
__license__ = &#34;None&#34;
import telegram_bot.helper_functions as hf
import investpy
import pandas
from currency_converter import CurrencyConverter
def get_share_price(str_search_for):
&#34;&#34;&#34;get stock price per share for company name or isin or symbol
Args:
str_search_for (string): search for this string/isin
Returns: none
&#34;&#34;&#34;
try:
search_result = investpy.search_quotes(text=str_search_for, products=[&#39;stocks&#39;], n_results=1, countries=[&#39;germany&#39;])
currency = str(search_result.retrieve_currency()) # retrieve currency from data
# should always be Euro because of countries=[&#39;germany&#39;]
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
stock_price = recent_data.iloc[-1][&#34;Close&#34;] # retrieve latest stock price
stock_price = round(float(stock_price), 2)
str_return =str(stock_price) + &#34; &#34; + 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=[&#39;stocks&#39;], n_results=1)
currency = str(search_result.retrieve_currency())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
#convert stock price from currency to EUR
stock_price = my_Converter.convert(float(stock_price), str(currency), &#39;EUR&#39;)
stock_price = round(float(stock_price), 2)
str_return = str(stock_price) + &#34; EUR&#34;
return str_return
except RuntimeError:
return &#34;None&#34;
def get_share_price_no_currency(str_search_for):
&#34;&#34;&#34;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
&#34;&#34;&#34;
try:
search_result = investpy.search_quotes(text=str_search_for, products=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
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=[&#39;stocks&#39;], n_results=1)
currency = str(search_result.retrieve_currency())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
stock_price = my_Converter.convert(float(stock_price), str(currency), &#39;EUR&#39;)
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=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
str_return = &#34;Company: &#34; + search_result.name + &#34;\nSymbol: &#34; + search_result.symbol + &#34;\nCurrent Price/Share: &#34; + 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=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
except RuntimeError as e:
return hf.make_markdown_proof(f&#34;no shares found for \&#34;{str_search_for}\&#34;&#34;) # if no shares are found, make error message markdown proof and return
except ConnectionError as e:
return hf.make_markdown_proof(f&#34;connection not possible. Try again later.&#34;) # if no connection, make error message markdown proof and return
str_return = f&#39;*{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))}&#39;
return str_return
def get_share_information_simple(str_search_for):
search_result = investpy.search_quotes(text=str_search_for, products=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
str_return = search_result.name + &#34;\n&#34; + search_result.symbol + &#34;\nworth: &#34; + get_share_price(str_search_for)
return str_return
if __name__ == &#34;__main__&#34;:
print(&#34;None&#34;)</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=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
str_return = &#34;Company: &#34; + search_result.name + &#34;\nSymbol: &#34; + search_result.symbol + &#34;\nCurrent Price/Share: &#34; + 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=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
except RuntimeError as e:
return hf.make_markdown_proof(f&#34;no shares found for \&#34;{str_search_for}\&#34;&#34;) # if no shares are found, make error message markdown proof and return
except ConnectionError as e:
return hf.make_markdown_proof(f&#34;connection not possible. Try again later.&#34;) # if no connection, make error message markdown proof and return
str_return = f&#39;*{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))}&#39;
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=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
str_return = search_result.name + &#34;\n&#34; + search_result.symbol + &#34;\nworth: &#34; + 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> :&ensp;<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):
&#34;&#34;&#34;get stock price per share for company name or isin or symbol
Args:
str_search_for (string): search for this string/isin
Returns: none
&#34;&#34;&#34;
try:
search_result = investpy.search_quotes(text=str_search_for, products=[&#39;stocks&#39;], n_results=1, countries=[&#39;germany&#39;])
currency = str(search_result.retrieve_currency()) # retrieve currency from data
# should always be Euro because of countries=[&#39;germany&#39;]
recent_data = pandas.DataFrame(search_result.retrieve_recent_data()) # stock prices of last few days
stock_price = recent_data.iloc[-1][&#34;Close&#34;] # retrieve latest stock price
stock_price = round(float(stock_price), 2)
str_return =str(stock_price) + &#34; &#34; + 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=[&#39;stocks&#39;], n_results=1)
currency = str(search_result.retrieve_currency())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
#convert stock price from currency to EUR
stock_price = my_Converter.convert(float(stock_price), str(currency), &#39;EUR&#39;)
stock_price = round(float(stock_price), 2)
str_return = str(stock_price) + &#34; EUR&#34;
return str_return
except RuntimeError:
return &#34;None&#34;</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> :&ensp;<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):
&#34;&#34;&#34;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
&#34;&#34;&#34;
try:
search_result = investpy.search_quotes(text=str_search_for, products=[&#39;stocks&#39;],
countries=[&#39;germany&#39;], n_results=1)
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
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=[&#39;stocks&#39;], n_results=1)
currency = str(search_result.retrieve_currency())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1][&#34;Close&#34;]
stock_price = my_Converter.convert(float(stock_price), str(currency), &#39;EUR&#39;)
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>

View File

@ -230,7 +230,8 @@ def update_for_user(message):
if len(share_symbols) != 0:
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: {share_amounts[i]}\nTotal: {hf.make_markdown_proof(round(float(my_price) * float(share_amounts[i]), 2))} EUR'
amounts = hf.make_markdown_proof(share_amounts[i])
my_update_message = f'{share_fetcher.get_share_information_markdown(share_symbols[i])}\ncount: {amounts}\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)
@ -464,7 +465,7 @@ def remove_share(message):
"""
user_id = int(message.from_user.id)
bot.send_message(chat_id=user_id, text='Type ISIN/Symbol/CompanyName of share to remove (if you are unsure do /portfolio, find your share and insert the value above amount):')
bot.send_message(chat_id=user_id, text='Type ISIN/Symbol/CompanyName of share to remove (if you are unsure do /shares, find your share and insert the value above amount):')
bot.register_next_step_handler(message, remove_share_step) # wait for user to send ISIN, then call remove_share_step function