env check

This commit is contained in:
prabhatdev
2020-07-27 02:26:22 +05:30
parent 4176c0f17e
commit d0a6e2667d
3 changed files with 144 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.env

104
loc_test.py Normal file
View File

@@ -0,0 +1,104 @@
import re
import os
import base64
import requests
from github import Github
import datetime
from string import Template
import matplotlib.pyplot as plt
from io import StringIO,BytesIO
username = ''
waka_key = '1647f145-ce70-4172-9f4c-aa9143300891'
ghtoken = '20c2809f702a3db2cbe2350dd160e4e34302889e'
userInfoQuery = """
{
viewer {
login
id
}
}
"""
repositoryListQuery = Template("""
{
user(login: "$username") {
repositories(orderBy: {field: CREATED_AT, direction: ASC}, first: 100, affiliations: [OWNER, COLLABORATOR, ORGANIZATION_MEMBER]) {
totalCount
edges {
node {
object(expression:"master") {
... on Commit {
history {
totalCount
}
}
}
primaryLanguage {
color
name
id
}
stargazers {
totalCount
}
collaborators {
totalCount
}
createdAt
name
owner {
id
login
}
nameWithOwner
}
}
}
location
createdAt
name
}
}
""")
def run_query(query):
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
return request.json()
else:
raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))
def getLoc():
result = run_query(repositoryListQuery.substitute(username=username))
# for repo in result['data']['user']['repositories']['edges']:
# print(repo)
if __name__ == '__main__':
try:
g = Github(ghtoken)
headers = {"Authorization": "Bearer " + ghtoken}
user_data = run_query(userInfoQuery) # Execute the query
username = user_data["data"]["viewer"]["login"]
id = user_data["data"]["viewer"]["id"]
print("user {} id {}".format(username, id))
getLoc()
# repo = g.get_repo(f"{username}/{username}")
# contents = repo.get_readme()
# waka_stats = get_stats()
# rdmd = decode_readme(contents.content)
# new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
# print(new_readme)
# # if new_readme != rdmd:
# repo.update_file(path=contents.path, message='Updated with Dev Metrics',
# content=new_readme, sha=contents.sha, branch='master')
# print("Readme updated")
except Exception as e:
print("Exception Occurred" + str(e))

39
temp.py Normal file
View File

@@ -0,0 +1,39 @@
def generate_repo_list():
result = run_query(repositoryListQuery.substitute(username=user))
language_count={}
for repo in result['data']['user']['repositories']['edges']:
if repo['node']['primaryLanguage'] is None:
continue
language=repo['node']['primaryLanguage']['name']
color_code=repo['node']['primaryLanguage']['color']
if language not in language_count.keys():
language_count[language]={}
language_count[language]['count']=1
language_count[language]['color']=color_code
else:
language_count[language]['count']=language_count[language]['count']+1
language_count[language]['color']=color_code
labels = language_count.keys()
sizes = list(map(lambda x: language_count[x]['count'] , labels))
colors = list(map(lambda x: language_count[x]['color'] , labels))
explode = tuple(map(lambda x: 0 , labels))
# Plot
patches, texts = plt.pie(sizes ,colors=colors, startangle=140, radius=1,labels=labels)
# plt.legend(patches, labels, loc='center right', bbox_to_anchor=(1, 0.5),
# fontsize=8, bbox_transform=plt.gcf().transFigure)
# plt.subplots_adjust(left=0.0, bottom=0.1, right=2)
plt.savefig('repo.png',bbox_inches="tight")
g = Github(ghtoken)
repo = g.get_repo(f"{user}/{user}")
with open('repo.png', 'rb') as input_file:
data = input_file.read()
try:
contents = repo.get_contents("charts/repo.png")
repo.update_file(contents.path, "Charts Added", data, contents.sha)
except Exception as e:
repo.create_file("charts/repo.png", "Initial Commit",data)
print("pushed")