mirror of
https://github.com/developersIndia/deviras.git
synced 2024-09-08 05:05:35 +05:30
send data from script
This commit is contained in:
parent
a9cb37dbd3
commit
f7a559aeb7
11
.github/workflows/flair-usage-stats.yml
vendored
11
.github/workflows/flair-usage-stats.yml
vendored
@ -23,12 +23,9 @@ jobs:
|
||||
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
|
||||
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
|
||||
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }}
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
run: |
|
||||
cd user-flair-usage
|
||||
python_output=$(python main.py)
|
||||
echo "::set-output name=python_output::$python_output"
|
||||
- name: Send Discord message
|
||||
env:
|
||||
WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" -d "{\"content\":\"$python_output\"}" $WEBHOOK_URL
|
||||
python -m pip install --upgrade pip
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
python main.py
|
@ -2,11 +2,13 @@ import praw
|
||||
from collections import defaultdict
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
|
||||
client_id = os.environ["REDDIT_CLIENT_ID"]
|
||||
client_secret = os.environ["REDDIT_CLIENT_SECRET"]
|
||||
reddit_pass = os.environ["REDDIT_PASSWORD"]
|
||||
username = os.environ["REDDIT_USERNAME"]
|
||||
webhook_url = os.environ["DISCORD_WEBHOOK_URL"]
|
||||
user_agent = 'User Flair Usage'
|
||||
sub = "developersIndia"
|
||||
|
||||
@ -63,9 +65,6 @@ for flair, count in sorted_flairs:
|
||||
else:
|
||||
old_available_flair_count[flair] += count
|
||||
|
||||
# Print the usage count of each available flair
|
||||
# for flair, count in available_flair_count.items():
|
||||
# print(f"Flair: {flair}, Usage Count: {count}")
|
||||
|
||||
total_count = sum(available_flair_count.values())
|
||||
old_flairs_total_count = sum(old_available_flair_count.values())
|
||||
@ -76,12 +75,12 @@ old_flairs_total_count = sum(old_available_flair_count.values())
|
||||
# print(f"Total count of user-flairs: {total_count + emoji_flair_count + old_flairs_total_count}")
|
||||
|
||||
data = {
|
||||
'Users with un-supported (old) text flairs': old_flairs_total_count,
|
||||
'Users with supported text flairs': total_count,
|
||||
'Users with emoji only flairs': emoji_flair_count,
|
||||
'Total count of user-flairs': total_count + emoji_flair_count + old_flairs_total_count
|
||||
'Users with un-supported (old) text flairs': f"**{old_flairs_total_count}**",
|
||||
'Users with supported text flairs': f"**{total_count}**",
|
||||
'Users with emoji only flairs': f"**{emoji_flair_count}**",
|
||||
'Total count of user-flairs': f"**{total_count + emoji_flair_count + old_flairs_total_count}**"
|
||||
}
|
||||
|
||||
formatted_data = json.dumps(data, indent=4) # Format the data as JSON with indentation
|
||||
formatted_data = "\n".join([f"{k}: {v}" for k, v in data.items()]) # Format the data as a string with each item on a new line
|
||||
|
||||
print(formatted_data)
|
||||
requests.post(webhook_url, json={"content": formatted_data})
|
2
user-flair-usage/requirements.txt
Normal file
2
user-flair-usage/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
praw
|
||||
requests
|
Loading…
Reference in New Issue
Block a user