this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add mlbhomeruns custom feeds

+115 -3
+2
feed_manager.py
··· 3 3 from feeds.battle import BattleFeed 4 4 from feeds.rapidfire import RapidFireFeed 5 5 from feeds.popular import PopularFeed 6 + from feeds.homeruns import HomeRunsTeamFeed 6 7 7 8 class FeedManager: 8 9 def __init__(self): ··· 42 43 feed_manager.register(BattleFeed) 43 44 feed_manager.register(RapidFireFeed) 44 45 feed_manager.register(PopularFeed) 46 + feed_manager.register(HomeRunsTeamFeed)
+1 -1
feedgen.py
··· 22 22 async def firehose_events(firehose_manager): 23 23 relay_url = 'wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos' 24 24 seq = firehose_manager.get_sequence_number() 25 - if seq: 25 + if seq is not None: 26 26 relay_url += f'?cursor={seq}' 27 27 28 28 logger = logging.getLogger('feeds.events')
+3
feeds/__init__.py
··· 7 7 def serve_feed(self, limit, offset, langs): 8 8 raise NotImplementedError 9 9 10 + def serve_wildcard_feed(self, feed_uri, limit, offset, langs): 11 + raise NotImplementedError 12 + 10 13 def commit_changes(self): 11 14 raise NotImplementedError 12 15
+109
feeds/homeruns.py
··· 1 + import logging 2 + 3 + import apsw 4 + import apsw.ext 5 + 6 + from . import BaseFeed 7 + 8 + MLBHRS_DID = 'did:plc:pnksqegntq5t3o7pusp2idx3' 9 + 10 + TEAM_ABBR_LOOKUP = { 11 + "OAK":"OaklandAthletics", 12 + "PIT":"PittsburghPirates", 13 + "SDN":"SanDiegoPadres", 14 + "SEA":"SeattleMariners", 15 + "SFN":"SanFranciscoGiants", 16 + "SLN":"StLouisCardinals", 17 + "TBA":"TampaBayRays", 18 + "TEX":"TexasRangers", 19 + "TOR":"TorontoBlueJays", 20 + "MIN":"MinnesotaTwins", 21 + "PHI":"PhiladelphiaPhillies", 22 + "ATL":"AtlantaBraves", 23 + "CHA":"ChicagoWhiteSox", 24 + "MIA":"MiamiMarlins", 25 + "NYA":"NewYorkYankees", 26 + "MIL":"MilwaukeeBrewers", 27 + "LAA":"LosAngelesAngels", 28 + "ARI":"ArizonaDiamondbacks", 29 + "BAL":"BaltimoreOrioles", 30 + "BOS":"BostonRedSox", 31 + "CHN":"ChicagoCubs", 32 + "CIN":"CincinnatiReds", 33 + "CLE":"ClevelandGuardians", 34 + "COL":"ColoradoRockies", 35 + "DET":"DetroitTigers", 36 + "HOU":"HoustonAstros", 37 + "KCA":"KansasCityRoyals", 38 + "LAN":"LosAngelesDodgers", 39 + "WAS":"WashingtonNationals", 40 + "NYN":"NewYorkMets", 41 + } 42 + 43 + class HomeRunsTeamFeed(BaseFeed): 44 + FEED_URI = 'at://did:plc:pnksqegntq5t3o7pusp2idx3/app.bsky.feed.generator/team:*' 45 + 46 + def __init__(self): 47 + self.db_cnx = apsw.Connection('db/homeruns.db') 48 + self.db_cnx.pragma('journal_mode', 'WAL') 49 + self.db_cnx.pragma('wal_autocheckpoint', '0') 50 + 51 + with self.db_cnx: 52 + self.db_cnx.execute(""" 53 + create table if not exists posts (uri text, tag text); 54 + create index if not exists tag_idx on posts(tag); 55 + """) 56 + 57 + self.logger = logging.getLogger('feeds.homeruns') 58 + 59 + def process_commit(self, commit): 60 + if commit['repo'] != MLBHRS_DID: 61 + return 62 + 63 + op = commit['op'] 64 + if op['action'] != 'create': 65 + return 66 + 67 + collection, _ = op['path'].split('/') 68 + if collection != 'app.bsky.feed.post': 69 + return 70 + 71 + record = op.get('record') 72 + if record is None: 73 + return 74 + 75 + uri = 'at://{repo}/{path}'.format( 76 + repo = commit['repo'], 77 + path = op['path'] 78 + ) 79 + tags = record.get('tags', []) 80 + 81 + self.logger.debug(f'adding {uri!r} under {tags!r}') 82 + 83 + with self.db_cnx: 84 + for tag in tags: 85 + self.db_cnx.execute( 86 + "insert into posts (uri, tag) values (:uri, :tag)", 87 + dict(uri=uri, tag=tag) 88 + ) 89 + 90 + def commit_changes(self): 91 + self.logger.debug('committing changes') 92 + self.wal_checkpoint(self.db_cnx, 'RESTART') 93 + 94 + def serve_wildcard_feed(self, feed_uri, limit, offset, langs): 95 + prefix, sep, team_abbr = feed_uri.rpartition(':') 96 + team_tag = TEAM_ABBR_LOOKUP[team_abbr] 97 + 98 + cur = self.db_cnx.execute(""" 99 + select uri 100 + from posts 101 + where tag = :tag 102 + order by uri desc 103 + limit :limit offset :offset 104 + """, dict(tag=team_tag, limit=limit, offset=offset)) 105 + 106 + return [uri for (uri,) in cur] 107 + 108 + def serve_wildcard_feed_debug(self, feed_uri, limit, offset, langs): 109 + pass
-2
feedweb.py
··· 6 6 from werkzeug.datastructures import LanguageAccept 7 7 8 8 from feed_manager import feed_manager 9 - from feeds.rapidfire import RapidFireFeed 10 - from feeds.popular import PopularFeed 11 9 12 10 feed_requests = Counter('feed_requests', 'requests by feed URI', ['feed']) 13 11