Created
January 15, 2016 23:07
-
-
Save maartenberg/4ed8fdc98693113d31a4 to your computer and use it in GitHub Desktop.
Parses the evil overlord rulelists and creates a fortune file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' Downloads and parses the Evil Overlord ruleset into a fortune file. ''' | |
| from bs4 import BeautifulSoup | |
| import requests | |
| import logging | |
| logging.basicConfig(level=logging.INFO) | |
| URLS = [ | |
| 'http://www.eviloverlord.com/lists/overlord.html', | |
| 'http://www.eviloverlord.com/lists/dungeon_a.html', | |
| 'http://www.eviloverlord.com/lists/dungeon_b.html', | |
| ] | |
| RULES = [] | |
| for url in URLS: | |
| logging.info('Now downloading %s', url) | |
| r = requests.get(url) | |
| soup = BeautifulSoup(r.text, 'html.parser') | |
| read_rules = [item for item in soup.ol.text.split('\n') | |
| if item != ''] | |
| logging.info('Read %s rules', len(read_rules)) | |
| RULES += read_rules | |
| count = 1 | |
| with open('output.txt', 'w') as file_: | |
| logging.info('Writing') | |
| for rule in RULES: | |
| file_.write('Evil Overlord Rule {}: {}\n'.format(count, rule)) | |
| count = count + 1 | |
| if rule != RULES[-1]: | |
| file_.write('%\n') | |
| logging.info('Done.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment