From df213fb36a5381df575d99ea2fb736156524c3f3 Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Sat, 16 Dec 2023 18:31:34 +0530 Subject: [PATCH] new scripts & readme --- README.md | 12 ++++-- community-threads-grabber/__init__.py | 0 community-threads-grabber/main.py | 58 +++++++++++++++++++++++++++ idcard_update/README.md | 10 +++++ 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 community-threads-grabber/__init__.py create mode 100644 community-threads-grabber/main.py create mode 100644 idcard_update/README.md diff --git a/README.md b/README.md index c104415..7ccd64d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,14 @@ Used for changing the text below total members & live members count in a subreddit. -![r/developersIndia About widget](https://user-images.githubusercontent.com/34342551/185678556-e4c911c9-fb12-49da-9ca6-8f8ce2ad9b5a.png) +### [aoc](https://github.com/developersIndia/deviras/blob/aoc) + +Used for updating the Advent of Code leaderboard in the [post](https://www.reddit.com/r/developersIndia/comments/1889ar3/advent_of_code_rdevelopersindia_leaderboard_year/). + +### [job_thread](https://github.com/developersIndia/deviras/blob/job_thread) + +Used for creating [hiring threads](https://www.reddit.com/r/developersIndia/?f=flair_name%3A%22Hiring%22) in the subreddit that gets the job from our [job board](https://developersindia.in/job-board/). + ## Setup @@ -40,9 +47,6 @@ Used for changing the text below total members & live members count in a subredd python -m unittest ``` -## Resources & Learning Material - -- [PRAW Docs](https://praw.readthedocs.io/en/stable/code_overview/other/idcard.html) ## Contributors ✨ diff --git a/community-threads-grabber/__init__.py b/community-threads-grabber/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/community-threads-grabber/main.py b/community-threads-grabber/main.py new file mode 100644 index 0000000..1361a2d --- /dev/null +++ b/community-threads-grabber/main.py @@ -0,0 +1,58 @@ +import praw +import os +from datetime import datetime +import json + +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"] + + +def get_collection(reddit): + collection = reddit.subreddit("developersIndia").collections( + permalink="https://reddit.com/r/developersIndia/collection/958aef35-f9cb-414d-ab33-08bc639e47de" + ) + return collection + + +def main(): + reddit = praw.Reddit( + client_id=client_id, + client_secret=client_secret, + username=username, + password=reddit_pass, + user_agent=f"Automod reader by u/{username}", + ) + + collection = get_collection(reddit) + + print(f"Last updated: {datetime.utcfromtimestamp(collection.last_update_utc)}") + + posts = [] + + for submission_id in collection.sorted_links: + submission = reddit.submission(submission_id) + post = { + "title": submission.title, + "url": submission.url, + "id": submission.id, + "num_comments": submission.num_comments, + "created_at": datetime.utcfromtimestamp(submission.created_utc).isoformat(), + "flair_text": submission.link_flair_text, + } + posts.append(post) + + collection_json = { + "collection_last_updated": datetime.utcfromtimestamp( + collection.last_update_utc + ).isoformat(), + "posts": posts, + } + + with open("collection.json", "w") as f: + json.dump(collection_json, f, indent=4) + + +if __name__ == "__main__": + main() diff --git a/idcard_update/README.md b/idcard_update/README.md new file mode 100644 index 0000000..c1bde02 --- /dev/null +++ b/idcard_update/README.md @@ -0,0 +1,10 @@ +## idcard_update + +Used for changing the text below total members & live members count in a subreddit. + +![r/developersIndia About widget](https://user-images.githubusercontent.com/34342551/185678556-e4c911c9-fb12-49da-9ca6-8f8ce2ad9b5a.png) + + +## Resources & Learning Material + +- [PRAW Docs](https://praw.readthedocs.io/en/stable/code_overview/other/idcard.html) \ No newline at end of file