Перешел на wakapi, жду пока данные обновятся
This commit is contained in:
parent
3c6d5cb5ca
commit
d34f9c6ef8
2 changed files with 23 additions and 28 deletions
32
main.py
32
main.py
|
@ -14,10 +14,10 @@ from datetime import datetime
|
|||
from models.Project import Project
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import config
|
||||
|
||||
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', dest='host', type=str, help='Hostname of the server')
|
||||
|
@ -59,36 +59,27 @@ def load_projects():
|
|||
repos.clear()
|
||||
for repo in resp['data']:
|
||||
repos.append(Project(repo["name"], repo["description"], repo["html_url"]))
|
||||
print(f'{datetime.now()}: Projects updated')
|
||||
logging.info(f'{datetime.now()}: Projects updated')
|
||||
except Exception as e:
|
||||
print(f'{datetime.now()}: Error while updating projects: {e}')
|
||||
logging.error(f'{datetime.now()}: Error while updating projects: {e}')
|
||||
time.sleep(7200)
|
||||
|
||||
|
||||
def load_code_stats():
|
||||
while True:
|
||||
try:
|
||||
resp = requests.get("https://wakatime.com/api/v1/users/Mootfrost/stats/").json()
|
||||
resp = requests.get('https://waka.mootfrost.ru/api/compat/wakatime/v1/users/Mootfrost/stats/last_7_days').json()
|
||||
global code_stats
|
||||
code_stats.clear()
|
||||
|
||||
total = resp['data']['categories'][0]
|
||||
code_stats['total'] = get_declension(total['hours'], 'час', 'часа', 'часов') + ' ' + \
|
||||
get_declension(total['minutes'], 'минуту', 'минуты', 'минут')
|
||||
|
||||
# WakaTime дает рэйндж только в хьюман ридбил формате, а не в дате...
|
||||
code_stats['since'] = datetime.strptime(resp['data']['human_readable_range']
|
||||
.replace('since ', ''), '%b %d %Y') \
|
||||
.strftime('%d.%m.%Y')
|
||||
|
||||
langs = resp['data']['languages']
|
||||
|
||||
code_stats['languages'] = {}
|
||||
for lang in langs[:5]:
|
||||
code_stats['languages'][lang['name']] = f"{round(lang['percent'])}%"
|
||||
print(f'{datetime.now()}: Code stats updated')
|
||||
for lang in resp['data']['languages'][:5]:
|
||||
code_stats['languages'][lang['name']] \
|
||||
= get_declension(lang['hours'], 'час', 'часа', 'часов') + ' ' + \
|
||||
get_declension(lang['minutes'], 'минуту', 'минуты', 'минут')
|
||||
logging.info(f'{datetime.now()}: Code stats updated')
|
||||
except Exception as e:
|
||||
print(f'{datetime.now()}: Error while updating code stats: {e}')
|
||||
logging.error(f'{datetime.now()}: Error while updating code stats: {e}')
|
||||
time.sleep(7200)
|
||||
|
||||
|
||||
|
@ -111,7 +102,8 @@ def get_code_stats():
|
|||
@app.get("/api/get_age")
|
||||
def get_age():
|
||||
today = datetime.today()
|
||||
return today.year - config.birthdate.year - ((today.month, today.day) < (config.birthdate.month, config.birthdate.day))
|
||||
return today.year - config.birthdate.year - (
|
||||
(today.month, today.day) < (config.birthdate.month, config.birthdate.day))
|
||||
|
||||
|
||||
@app.get("/")
|
||||
|
|
|
@ -31,10 +31,11 @@
|
|||
</div>
|
||||
<div class="contents-div description-container">
|
||||
<p class="about-contents" id="about">
|
||||
Семейкин Андрей, {age} лет. Живу в Москве<br><br>
|
||||
В основном пишу на C#, Python, JS. Немного знаю C++<br>
|
||||
Семейкин Андрей, {age} лет. Живу в Москве<br><br>
|
||||
В основном пишу на C#, Python, JS. Немного знаю C++, Java<br>
|
||||
</p>
|
||||
<p class="about-contents" id="code-stats">
|
||||
За последнюю неделю на:<br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -53,15 +54,17 @@
|
|||
},
|
||||
);
|
||||
let code_stats = await resp.json()
|
||||
|
||||
let about = document.getElementById('code-stats')
|
||||
|
||||
about.innerHTML += `С ${code_stats['since']}: ` + code_stats['total'] + '<br/>'
|
||||
about.innerHTML += 'Из них на:' + '<br/>'
|
||||
|
||||
for (let language in code_stats['languages']) {
|
||||
about.innerHTML += language + ' - ' + code_stats['languages'][language] + '<br>'
|
||||
if(Object.keys(code_stats).length === 0) {
|
||||
about.innerHTML += '❌Не удалось загрузить❌'
|
||||
return
|
||||
}
|
||||
|
||||
for (let lang in code_stats['languages']) {
|
||||
about.innerHTML += lang + ' - ' + code_stats['languages'][lang] + '<br>'
|
||||
}
|
||||
about.innerHTML += ''
|
||||
}
|
||||
load_code_stats()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue