Files
titlebot-ng-ng/__pycache__/get_user_list.cpython-314.pyc
T

114 lines
14 KiB
Plaintext
Raw Normal View History

2026-08-06 21:34:52 -05:00
+
2026-08-12 17:14:01 -05:00
î|j§+ãó¸Rt^RIt^RIt^RIt^RIt^RIt^RIt^RIHtH t H
t
H t ^RI H
2026-08-06 21:34:52 -05:00
t
!RR4tRt]R8Xd]P"!]!44R#R#)
2026-08-12 17:14:01 -05:00
Python script that reads configs/config.yaml and scrapes a list of active users from the Matrix room.
2026-08-06 21:34:52 -05:00
Stores the user list in a SQLite database named after the room.
2026-08-12 17:14:01 -05:00
N)Ú AsyncClientÚ
LoginResponseÚRoomMessagesResponseÚ SyncResponse)ÚRoomcóXa]tRt^toRtR RltRtRtRtRt Rt
Rt R t R
2026-08-06 21:34:52 -05:00
t
VtR #)
ÚUserListManagerz@Manages collection and storage of active users in a Matrix room.có~\V4Vn.VnVP4VnVP 4R#)N)rÚroomÚusersÚget_user_db_pathÚdb_pathÚ init_user_db)ÚselfÚ config_paths&&Ú//home/nolan/dev/titlebot-ng-ng/get_user_list.pyÚ__init__ÚUserListManager.__init__s1ܘӌ ؈Œ
Ø×Œ Ø ×ÑÖóc óz\P!RRVPPP4pRV R2#)zFGenerate database path for user list, similar to suggestions database.z[^a-zA-Z0-9_-]Úusers_z.db)ÚreÚsubr
ÚconfigÚroom_id)rÚsafes& rr Ú UserListManager.get_user_db_paths4ävŠvШd¯i©i×.>Ñ.>×.FÑ.FÓGˆØ˜v˜!rc óf\P!VP4pVP4pVP R4VP R4VP 4Uu.uF q3^,NK
ppRV9dVP R4RV9dVP R4VP R4VP R4VP 4Uu.uF q3^,NK
ppR V9dVP R
4VP
4VP4R #uupiuupi) z"Initialize the user list database.a‰
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT UNIQUE,
display_name TEXT,
last_seen INTEGER,
last_updated INTEGER,
num_posts INTEGER DEFAULT 0,
last_active INTEGER DEFAULT 0,
UNIQUE(user_id)
)
2026-08-12 17:14:01 -05:00
zPRAGMA table_info(users)Ú num_postsz8ALTER TABLE users ADD COLUMN num_posts INTEGER DEFAULT 0Ú last_activez:ALTER TABLE users ADD COLUMN last_active INTEGER DEFAULT 0a
2026-08-06 21:34:52 -05:00
CREATE TABLE IF NOT EXISTS fetch_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp INTEGER,
user_count INTEGER,
2026-08-12 17:14:01 -05:00
datetime TEXT,
2026-08-06 21:34:52 -05:00
most_recent_post INTEGER DEFAULT 0
2026-08-12 17:14:01 -05:00
)
zPRAGMA table_info(fetch_log)Úmost_recent_postzCALTER TABLE fetch_log ADD COLUMN most_recent_post INTEGER DEFAULT 0N)Úsqlite3Úconnectr
ÚcursorÚexecuteÚfetchallÚcommitÚclose)rÚconnÚrowÚcolss& rrÚUserListManager.init_user_db䊘tŸ|™|ÓØ K‰K‹MˆØ ‰ ð  ô
ð
‰ Ð-Ø"#§*¡*¤,Ó/¡,˜3A—¡,ˆÐ ˜
I‰IÐ  Ô
I‰IÐ 
‰ ð ô
ð
‰ Ð1Ø"#§*¡*¤,Ó/¡,˜3A—¡,ˆÐ  TÔ
I‰IÐ  Œ
2026-08-06 21:34:52 -05:00
Ø
2026-08-12 17:14:01 -05:00
Ž ùò/0ùò$0s Á%D)ÃD.cƒ ó¸"VPP4GRjxL
'g\R4.#VPPP RR7GRjxL
p\ V\ 4'g\RV 24VPPPPVPPP4pV'g/\RVPPP 24.#\R4VP4GRjxL
wr4p.pVPF}pVPPV4GRjxL
2026-08-06 21:34:52 -05:00
pVPRVR VR
2026-08-12 17:14:01 -05:00
\\ P !44R VPV^4R VPV^4/4K W`n WPnV#EELrLu5i)
z=Fetch all members from the Matrix room and count their posts.NzFailed to login to Matrixi¸ )Útimeoutz
2026-08-06 21:34:52 -05:00
Sync failed: zCould not find room z3Counting posts per user (this may take a moment)...Úuser_idÚ display_nameÚ last_seenrr )r
Úlogin_to_matrixÚprintÚclientÚsyncÚ
isinstancerÚroomsÚgetrrÚcount_user_postsr Úget_display_nameÚappendÚintÚtimer!) rÚ sync_respÚroom_objÚ post_countsÚ
last_activityr!r r0r1s & rÚget_room_membersÚ UserListManager.get_room_membersIs†éð—Y‘Y× Ð ˆIðŸ)™)×Ð=ˆ ܘ)¤\× M ) Ð —99×)×-¨d¯i©i×.>Ñ.>×.FÑ.FÓGˆßÜ Ð¯©×)9Ñ)9×)AÑ)AÐ(BÐ ˆ ÐDØ=A×=RÑ=RÓ=T×7TÑ4ˆ Ð$4àˆØ—~”~ˆGØ!%§¡×!;Ñ!;¸GÓ!D×DˆLØ L‰Lؘ7Ø  ØœS¤§¢£Ó˜[Ÿ_™_¨W°aÓ˜}׸!Ó ö
ñŒ
Ø 0ÔØˆ òA
8UñEùsSG G¡ G«6GÁ!GÁ"A<GÃA GÄ+GÄ,6GÅ"GÅ#A.GÇGÇGÇGcƒ óÒ"/p/p^pVPPPpVPPPpRp^pWu8EdfVPPP VPPP VVR7GRjxL
p\V\4'dVP'gMíV\VP4,
pVPp \V R4'gK\V R4'gK+V Pp
2026-08-12 17:14:01 -05:00
VPV
2026-08-06 21:34:52 -05:00
^4^,W&\V R4'gKf\V PR,4p W¢9gW²V
,8”dW²V
&W³8”gT p VP pV'dWu8¼dMEKlWV3#EL \"dp \%RT 24Rp ? K&Rp ? ii;i5i)zMCount total number of posts by each user in the room and track last activity.N)rÚstartÚlimitÚsenderÚbodyÚserver_timestampièzError fetching messages: )r
rÚ
batch_sizeÚuser_lookback_limitr5Ú
room_messagesrr7rÚchunkÚlenÚhasattrrHr9r=rJÚendÚ Exceptionr4)
2026-08-12 17:14:01 -05:00
rrArBr!rKÚlookback_limitÚ
next_batchÚfetchedÚresponseÚeventrHÚ
2026-08-06 21:34:52 -05:00
event_timeÚes
& rr:Ú UserListManager.count_user_postsnéàˆ Øˆ
ØÐØ—Y‘Y×
ØŸ×Øˆ
؈ðÕ"
Ø!%§¡×!1Ñ!1×!?Ñ!?Ø ŸI™I×,×"@ó"÷ô " (Ô,@×ÏÏÈØàœ3˜xŸ~™~Ó.à%Ÿ^œ^˜u h×/´G¸EÀ6×4JÔ4JØ!&§¡˜Ø.9¯o©o¸fÀaÓ.HÈ1Õ.L˜ Ñ# 5Ð*<×=Ü),¨U×-CÑ-CÀtÕ-KÓ)L˜:¸jÐY_ÕK`Ô>`Ø8B¨fÑ 5à<Ø3=Ò 0ñ&Ÿ\™\
÷" WÔ%>Øò&?ðÐ+;Ð;òGøô>ô
ÜÐ1°!°Ðûð
2026-08-12 17:14:01 -05:00
üsmAG'ÁA GÂF=Â+GÃ G'Ã :GÄ GÄ6GÅ6GÆGÆ/GÆ5G'Æ=GÇ G$Ç GÇG'ÇG$Ç$G'c
2026-08-06 21:34:52 -05:00
 óšVP'g\R4R#\P!VP4pVP 4p\
2026-08-12 17:14:01 -05:00
\P!44pVPFHpVPRVR,VR,VR,VVR,VPR^434KJ ^R
I H pVPR V\VP4VP4P4\VR ^434VP!4VP#4\R
\VP4 RVP 24R# \PdJTPR TR,TR,TTR,TPR^4TR,34EKOi;i)z&Write collected users to the database.zNo users to write to databaseNa 
INSERT INTO users (user_id, display_name, last_seen, last_updated, num_posts, last_active)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(user_id) DO UPDATE SET
2026-08-06 21:34:52 -05:00
display_name = excluded.display_name,
last_seen = excluded.last_seen,
last_updated = excluded.last_updated,
num_posts = excluded.num_posts,
last_active = excluded.last_active
r0r1r2rr
UPDATE users
SET display_name = ?, last_seen = ?, last_updated = ?, num_posts = ?, last_active = ?
2026-08-12 17:14:01 -05:00
WHERE user_id = ?
2026-08-06 21:34:52 -05:00
)Údatetimez
2026-08-12 17:14:01 -05:00
INSERT INTO fetch_log (timestamp, user_count, datetime, most_recent_post)
VALUES (?, ?, ?, ?)
2026-08-06 21:34:52 -05:00
r!zWrote z
users to )r r4r"r#r
2026-08-12 17:14:01 -05:00
r$r=r>r%r9ÚIntegrityErrorr\rOÚnowÚ isoformatÚgetattrr'r()rr)r*Ú current_timeÚuserr\s& rÚwrite_users_to_dbÚ!UserListManager.write_users_to_db sàzzˆzÜ Ð äŠ˜tŸ|™|ÓØ K‰K‹Mˆäœ4Ÿ9š9›;Ó à—J”Jˆ
2026-08-06 21:34:52 -05:00
Ø— ‘ ð ð˜•OØ˜Õ˜Õ Ø˜Õ—H‘H˜]¨AÓ
öñõF ‰ ð ðœC §
¡
O¨X¯\©\«^×-EÑ-EÓ-GÌÐQUÐWiÐklÓImÐ
2026-08-12 17:14:01 -05:00
 pð
2026-08-06 21:34:52 -05:00
Œ
2026-08-12 17:14:01 -05:00
Ø