Skip to content

Commit d24e511

Browse files
committed
Adding user counting script
1 parent 35c68c5 commit d24e511

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

.github/workflows/user-count.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run user-count script daily
2+
3+
on:
4+
schedule:
5+
- cron: "5 4 * * *"
6+
7+
jobs:
8+
report:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: action/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.13'
15+
- run: python3 user-count/arkscript-usage.py
16+
- name: Commit and push
17+
shell: bash
18+
run: |
19+
git config --unset-all http.https://github.com/.extraheader
20+
git config user.name "User count bot"
21+
git config user.email ""
22+
git config remote.origin.url 'https://${{ secrets.GITHUB_TOKEN }}@github.com/ArkScript-lang/stats.git'
23+
git add users.json
24+
git commit -m "Update stats"
25+
git push -u origin master
26+

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
users.json
3+

user-count/arkscript-usage.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import requests
2+
import dotenv
3+
import os
4+
import json
5+
import datetime
6+
7+
8+
dotenv.load_dotenv()
9+
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
10+
output = "users.json"
11+
12+
search = "extension:ark let OR MUT NOT repo:ark-lang/ark NOT is:fork"
13+
url_encoded = search.replace(":", "%3A").replace("*", "%2A").replace("/", "%2F").replace(" ", "+")
14+
url = f"https://api.github.com/search/code?q={url_encoded}"
15+
16+
response = requests.request("GET", url, headers={'Authorization': f'Token {GITHUB_TOKEN}'})
17+
data = response.json()
18+
19+
users = set()
20+
repositories = set()
21+
22+
for item in data['items']:
23+
repo = item['repository']
24+
users.add(repo['owner']['login'])
25+
repositories.add(repo['full_name'])
26+
27+
if os.path.exists(output):
28+
with open(output) as f:
29+
data = json.loads(f.read())
30+
else:
31+
data = {}
32+
33+
data[datetime.datetime.now().strftime("%Y-%m-%d")] = {
34+
'users': len(users),
35+
'repositories': len(repositories)
36+
}
37+
38+
with open(output, 'w') as f:
39+
f.write(json.dumps(data))
40+

0 commit comments

Comments
 (0)