From ad42f7497e98ac689606ba985f9288299e212d42 Mon Sep 17 00:00:00 2001 From: Haku Date: Sun, 15 Mar 2020 08:30:49 -0400 Subject: [PATCH] cleaned up update founderless function --- founderlessnotify/founderlessnotify.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/founderlessnotify/founderlessnotify.py b/founderlessnotify/founderlessnotify.py index b6acc82..5c1eb0a 100644 --- a/founderlessnotify/founderlessnotify.py +++ b/founderlessnotify/founderlessnotify.py @@ -18,18 +18,18 @@ def canonicalize(in_str): def get_founderless_regions(): """Return the list of founderless regions.""" + time.sleep(RATE_LIMIT) r = requests.get('https://www.nationstates.net/cgi-bin/api.cgi?q=regionsbytag;tags=founderless', headers=R_HEADERS) - time.sleep(RATE_LIMIT) tree = et.fromstring(r.text) return tree[0].text.split(',') def download_region_dump(): """Download the latest region dump from the NS API.""" + time.sleep(RATE_LIMIT) r = requests.get('https://www.nationstates.net/pages/regions.xml.gz', headers=R_HEADERS) - time.sleep(RATE_LIMIT) with open('regions.xml.gz', 'wb') as f: f.write(r.content) with gzip.open('regions.xml.gz', 'rb') as f_in: @@ -104,14 +104,12 @@ class FounderlessNotify(commands.Cog): # Get the region endos for both lists # now_foundered_endos = get_region_endos(now_foundered) now_founderless_endos = get_region_endos(now_founderless) - message_content = '' - await channel.send('The following regions are now **Founderless**:') + message_content = "The following regions are now **Founderless**:\n" for region in now_founderless: message_content += f"https://www.nationstates.net/region={canonicalize(region)} " \ - f"({now_founderless_endos[region]})" + f"({now_founderless_endos[region]})\n" for page in pagify(message_content): await channel.send(page) - await self.config.previous_founderless.set(new_founderless_regions) async def bg_loop(self):