Переглянути джерело

cleaned up update founderless function

master
Haku 5 роки тому
джерело
коміт
ad42f7497e
1 змінених файлів з 4 додано та 6 видалено
  1. +4
    -6
      founderlessnotify/founderlessnotify.py

+ 4
- 6
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):


Завантаження…
Відмінити
Зберегти