Skip to content

Commit 026c552

Browse files
committed
Got a very basic bot that just looks at my own account first.
1 parent 2f4f5ea commit 026c552

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
# psf-gsoc-fedibot
2+
23
A bot for Python-GSOC's Fediverse presence.
4+
5+
Making it easier to keep track of our participants, and inviting both participants and mentors to engage more in the community. Plus, it's written in Python! We figure we should be able to hack on our own infrastructure, in the project language.
6+
7+
## Features
8+
9+
- Keep track of participants' regular posts
10+
- Link participants, projects, and mentors
11+
- Produce reports
12+
- Promote projects?
13+
14+
## Contribute?
15+
16+
We're not really ready for outside contributions yet; so far, this is a proof of concept more than anything else. This project is run by [Ben](@ben@social.python-gsoc.org) in spare time.

src/main.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#
2+
3+
from mastodon import Mastodon
4+
from pathlib import PosixPath
5+
import os.path
6+
import argparse
7+
from datetime import datetime, timedelta, timezone
8+
import dateparser
9+
10+
python_gsoc_url = 'https://social.python-gsoc.org/'
11+
client_id = 'psf-gsoc-bot'
12+
cred_path = PosixPath('~/.psf-gsoc-bot/clientcred.secret').expanduser()
13+
14+
def check_recent_posts(client: Mastodon, account_name: str, deadline: datetime):
15+
today = datetime.now(timezone.utc)
16+
17+
week = timedelta(weeks=1)
18+
initial_window = deadline - week
19+
20+
# take an account name
21+
account = client.account_lookup(account_name)
22+
23+
# look up the posts, in order. Find the most recent.
24+
posts = client.account_statuses(account['id'], exclude_reblogs = True, exclude_replies = True, limit=10)
25+
print(f'Returned {len(posts)} posts.')
26+
27+
for post in posts:
28+
print(post)
29+
30+
if (len(posts) > 0):
31+
post = posts[0]
32+
postdate = post['created_at']
33+
print()
34+
# Record when the most recent post was
35+
print(f"Most recent post posted on: ({type(postdate)}) {postdate}, contents: {post['content']}")
36+
37+
# check the current date against the most recent deadline date.
38+
# if the most recent post is not within a week of the most recent deadline,
39+
if (today > deadline and postdate < initial_window):
40+
# log that they're behind.
41+
print(f"{account_name} hasn't posted in over a week.")
42+
# send them a message and flag them in a list to the mentors & admins
43+
44+
45+
46+
def register_app():
47+
print("Checking for registration.")
48+
if not cred_path.exists():
49+
print('No registration found.')
50+
if not cred_path.parent.exists():
51+
print(f'Config directory {cred_path.parent} missing.')
52+
cred_path.parent.mkdir()
53+
print(f'Registering as {client_id}.')
54+
Mastodon.create_app(
55+
client_id,
56+
api_base_url = python_gsoc_url,
57+
to_file = cred_path
58+
)
59+
60+
register_app()
61+
cred = cred_path.read_text()
62+
63+
mastodon = Mastodon(
64+
client_id,
65+
cred,
66+
api_base_url = python_gsoc_url
67+
)
68+
69+
parser = argparse.ArgumentParser(prog='python-gsoc bot',
70+
description='Checks up on users.')
71+
72+
parser.add_argument('-d', '--deadline')
73+
74+
args = parser.parse_args()
75+
76+
deadline = dateparser.parse(args.deadline)
77+
if deadline is None:
78+
print(f'{args.deadline} is not a correctly-formatted datetime.')
79+
exit(1)
80+
81+
print(f'Deadline: {args.deadline} parsed as {deadline}')
82+
83+
check_recent_posts(mastodon, 'ben@social.python-gsoc.org', deadline)
84+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy