💻 | Working on API

This commit is contained in:
2021-04-05 17:14:57 +02:00
parent 4483e9139e
commit 933109aceb
29 changed files with 201 additions and 463 deletions

View File

@@ -1,24 +1,13 @@
import {getDailyStats, getMonthlyStats, getTotalStats, getWeeklyStats} from "App/Helpers/StatsHelper";
import Redis from "@ioc:Adonis/Addons/Redis";
import axios from 'axios'
import Env from "@ioc:Adonis/Core/Env";
export async function UpdateGitHubReadme(): Promise<void> {
const daily_stats = await getDailyStats()
const weekly_stats = await getWeeklyStats()
const monthly = await getMonthlyStats()
const total_stats = await getTotalStats()
const sleeping = await Redis.get('artapi/states/sleeping')
const learning = await Redis.get('artapi/states/learning')
const developing = await Redis.get('artapi/states/developing')
const listening_music = await Redis.get('artapi/states/listening')
const stats_table = `| Statistics | Daily | Weekly | Monthly | Total |
| :------------------------------------------ | ----------: | ----------: | -----------: | -----------: |
| :computer: Commands | **${daily_stats.docker_commands_run}** | **${weekly_stats.docker_commands_run}** | **${monthly.docker_commands_run}** | **${total_stats.docker_commands_run}** |
| :hammer: Docker Builds | **${daily_stats.docker_build_count}** | **${weekly_stats.docker_build_count}** | **${monthly.docker_build_count}** | **${total_stats.docker_build_count}** |`
const infos_table = `| Informations | State |
| ---------------------------: | ------: |
| :musical_note: Music Playing | **${getStatus(listening_music)}** |
@@ -36,27 +25,17 @@ export async function UpdateGitHubReadme(): Promise<void> {
const content = Buffer.from(read_me.content, 'base64').toString()
const stats_table_check = '| Statistics' + content.split('| Statistics')[1]
if (!stats_table_check) change = true
const old_stats_table = stats_table_check.split('| Informations')[0]
if (!old_stats_table) change = true
const infos_table_check = '| Informations' + content.split('| Informations')[1]
if (!infos_table_check) change = true
const old_infos_table = infos_table_check.split('###### Curious')[0]
if (!old_infos_table) change = true
if (old_infos_table == infos_table && old_stats_table == stats_table) change = false
if (!change) return
let new_content = content.replace(old_stats_table, stats_table + '\n\n');
new_content = new_content.replace(old_infos_table, infos_table + '\n\n')
await axios.put('https://api.github.com/repos/ArthurDanjou/ArthurDanjou/contents/README.md',
{
message: 'Updating recent statistics & informations',
content: Buffer.from(new_content, 'utf8').toString('base64'),
content: Buffer.from(content.replace(old_infos_table, infos_table + '\n\n'), 'utf8').toString('base64'),
sha: read_me.sha,
author: {
name: 'api.arthurdanjou.fr - API Automation',