as-cle-bert commited on
Commit
97c7859
β€’
1 Parent(s): 0e24b58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -3,19 +3,24 @@ import pandas as pd
3
  from repos import get_repo_info
4
  from scrape import fetch_contribution_details, parse_contribution_details
5
  from plotly_im import plot_to_html, plot_pie_chart
 
 
6
 
7
  def reply(username: str, token: str):
8
  base_str = f"<h2 align='center'>What a git-year, {username}!πŸ₯‚πŸŽ‰</h2>\n\n<br>\n\n<div align='center'><img src='https://logos-world.net/wp-content/uploads/2020/11/GitHub-Logo.png' alt='GitHub Logo' width=150></div>\n\n\n"
 
9
  contributions = fetch_contribution_details(username, token)
10
  contrib_str = parse_contribution_details(contributions)
11
  repocount, gained_stars, gained_forks, top_10_topics, top_10_languages = get_repo_info(username, token)
12
  gainings_string = f"### βœ… This year's achievements\n\n- πŸ“ You created **{repocount} repositories**\n- ⭐ You gained **{gained_stars} new stars**\n- 🍴 You gained **{gained_forks} new forks**\n\n### πŸͺ› This year's contributions\n\n"
13
  base_str+=gainings_string
14
  base_str+=contrib_str
 
15
  top_10_tops = [f"- `{el[0]}` was used in {el[1]} of your repositories" for el in top_10_topics]
16
  top_10_langs = [f"- **{k}** accounted for **{top_10_languages[k]}%** of your code this year" for k in top_10_languages]
17
  tops_and_langs = "### πŸ““ Your Top 10 Topics This Year\n\n" + "\n".join(top_10_tops) + "\n\n" + "### πŸ’» Your Top 5 Languages This Year \n\n" + "\n".join(top_10_langs) + "\n\n"
18
  base_str+=tops_and_langs
 
19
  top_10_tops_df = pd.DataFrame.from_dict({"TOPIC": [el[0] for el in top_10_topics], "COUNT": [el[1] for el in top_10_topics]})
20
  top_10_langs_df = pd.DataFrame.from_dict({"LANGUAGE": list
21
  (top_10_languages.keys())+["Other"], "PERCENTAGE": list(top_10_languages.values())+[100-sum(list(top_10_languages.values()))]})
@@ -27,13 +32,18 @@ def reply(username: str, token: str):
27
  labels={"LANGUAGE": "Language", "PERCENTAGE": "Percentage"},
28
  title="Your Top 5 Languages This Year",
29
  filepath="language_usage"
30
- )
31
-
32
- return base_str, top_10_tops_img, top_10_langs_img
 
 
 
 
 
33
 
34
 
35
  mytheme = gr.themes.Monochrome(font=gr.themes.Font("sans-serif"))
36
 
37
- iface = gr.Interface(fn=reply, inputs=[gr.Textbox(label="GitHub Username", info="Insert your username here"), gr.Textbox(type="password", label="GitHub Token", info="Insert a GitHub token with repository-level access (<a href='https://github.com/settings/tokens'>find/create yours here</a>)")], outputs=[gr.Markdown(label="Your output will be displayed here"), gr.Image(label="Topics"), gr.Image(label="Languages")], title="<h1 align='center'>What A Git-Year!πŸ₯³</h1>\n<h2 align='center'>Find out about your contributions on GitHub in the last yearπŸ“†</h2>\n<br>", theme=mytheme)
38
 
39
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
3
  from repos import get_repo_info
4
  from scrape import fetch_contribution_details, parse_contribution_details
5
  from plotly_im import plot_to_html, plot_pie_chart
6
+ import markdown
7
+ from markdown_pdf import MarkdownPdf, Section
8
 
9
  def reply(username: str, token: str):
10
  base_str = f"<h2 align='center'>What a git-year, {username}!πŸ₯‚πŸŽ‰</h2>\n\n<br>\n\n<div align='center'><img src='https://logos-world.net/wp-content/uploads/2020/11/GitHub-Logo.png' alt='GitHub Logo' width=150></div>\n\n\n"
11
+ finstr = f"## What a git-year, {username}!πŸŽ‰\n\n"
12
  contributions = fetch_contribution_details(username, token)
13
  contrib_str = parse_contribution_details(contributions)
14
  repocount, gained_stars, gained_forks, top_10_topics, top_10_languages = get_repo_info(username, token)
15
  gainings_string = f"### βœ… This year's achievements\n\n- πŸ“ You created **{repocount} repositories**\n- ⭐ You gained **{gained_stars} new stars**\n- 🍴 You gained **{gained_forks} new forks**\n\n### πŸͺ› This year's contributions\n\n"
16
  base_str+=gainings_string
17
  base_str+=contrib_str
18
+ finstr += gainings_string + contrib_str
19
  top_10_tops = [f"- `{el[0]}` was used in {el[1]} of your repositories" for el in top_10_topics]
20
  top_10_langs = [f"- **{k}** accounted for **{top_10_languages[k]}%** of your code this year" for k in top_10_languages]
21
  tops_and_langs = "### πŸ““ Your Top 10 Topics This Year\n\n" + "\n".join(top_10_tops) + "\n\n" + "### πŸ’» Your Top 5 Languages This Year \n\n" + "\n".join(top_10_langs) + "\n\n"
22
  base_str+=tops_and_langs
23
+ finstr += tops_and_langs
24
  top_10_tops_df = pd.DataFrame.from_dict({"TOPIC": [el[0] for el in top_10_topics], "COUNT": [el[1] for el in top_10_topics]})
25
  top_10_langs_df = pd.DataFrame.from_dict({"LANGUAGE": list
26
  (top_10_languages.keys())+["Other"], "PERCENTAGE": list(top_10_languages.values())+[100-sum(list(top_10_languages.values()))]})
 
32
  labels={"LANGUAGE": "Language", "PERCENTAGE": "Percentage"},
33
  title="Your Top 5 Languages This Year",
34
  filepath="language_usage"
35
+ )
36
+ finstr += "\n\n![Topics](topics.png)\n\n![Languages](language_usage.png)"
37
+ pdf = MarkdownPdf(toc_level=0)
38
+ pdf.add_section(Section(finstr))
39
+ pdf.meta["title"] = f"{username}'s GitHub Year in Review"
40
+ output_pdf = "GitHub_Wrapped.pdf"
41
+ pdf.save(output_pdf)
42
+ return base_str, top_10_tops_img, top_10_langs_img, output_pdf
43
 
44
 
45
  mytheme = gr.themes.Monochrome(font=gr.themes.Font("sans-serif"))
46
 
47
+ iface = gr.Interface(fn=reply, inputs=[gr.Textbox(label="GitHub Username", info="Insert your username here"), gr.Textbox(type="password", label="GitHub Token", info="Insert a GitHub token with repository-level access (<a href='https://github.com/settings/tokens'>find/create yours here</a>)")], outputs=[gr.Markdown(label="Your output will be displayed here"), gr.Image(label="Topics"), gr.Image(label="Languages"), gr.File(label="Download your GitHub wrapped in PDF!")], title="<h1 align='center'>What A Git-Year!πŸ₯³</h1>\n<h2 align='center'>Find out about your contributions on GitHub in the last yearπŸ“†</h2>\n<br>", theme=mytheme)
48
 
49
  iface.launch(server_name="0.0.0.0", server_port=7860)