Skip to content

Instantly share code, notes, and snippets.

@Ray-Eldath
Last active December 29, 2022 17:33
Show Gist options
  • Save Ray-Eldath/08e9daf7eca64278c3c8e1b5bbdb8e59 to your computer and use it in GitHub Desktop.
Save Ray-Eldath/08e9daf7eca64278c3c8e1b5bbdb8e59 to your computer and use it in GitHub Desktop.
List your programming languages
from pprint import pprint
from gql import Client, gql
from gql.transport.aiohttp import AIOHTTPTransport
personal_api_token = 'YOUR PERSONAL TOKEN'
username = 'YOUR USERNAME'
def main():
transport = AIOHTTPTransport(url="https://api.github.com/graphql",
headers={
'Authorization': f'Bearer {personal_api_token}'
})
client = Client(transport=transport, fetch_schema_from_transport=True)
query = gql(
"""
query userInfo($login: String!) {
user(login: $login) {
# fetch only owner repos & not forks
repositories(ownerAffiliations: OWNER, isFork: false, first: 100) {
nodes {
name
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
edges {
size
node {
color
name
}
}
}
}
}
}
}
""")
d = client.execute(query, variable_values={"login": username})
pprint(d)
result = {}
exclude = ['HTML', 'Stylus', 'CSS']
for repo in d['user']['repositories']['nodes']:
for lang in repo['languages']['edges']:
name = lang['node']['name']
if name in exclude:
continue
size = lang['size']
if result.get(name) is None:
result[name] = size
else:
result[name] += size
result = sorted(result.items(), key=lambda e: e[1], reverse=True)
s = sum(map(lambda e: e[1], result))
for r in result:
print('{:<15} {:>6} - {:.1f}kB'.format(r[0], '{:.2f}'.format((r[1] / s) * 100) + '%', r[1] / 1000))
if __name__ == '__main__':
main()
@Ray-Eldath
Copy link
Author

Ray-Eldath commented Aug 2, 2021

  • pip install aiohttp gql
  • fill in your personal token and username. make sure user permission is granted
  • python main.py

and you'll get:

Kotlin          31.68% - 377.2kB
C++             14.09% - 167.8kB
Vue             13.45% - 160.2kB
JavaScript      10.96% - 130.5kB
Java             5.33% - 63.5kB
Rust             4.73% - 56.3kB
Scala            3.96% - 47.2kB
C#               3.80% - 45.2kB
Ruby             2.84% - 33.8kB
Standard ML      2.31% - 27.5kB
SystemVerilog    1.82% - 21.7kB
Go               1.31% - 15.6kB
Racket           1.23% - 14.6kB
Assembly         0.95% - 11.3kB
CMake            0.63% - 7.5kB
Python           0.45% - 5.4kB
Groovy           0.21% - 2.5kB
Shell            0.11% - 1.3kB
Dockerfile       0.06% - 0.7kB
Batchfile        0.05% - 0.6kB
Haskell          0.03% - 0.3kB
PowerShell       0.02% - 0.2kB

Process finished with exit code 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment