Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Destiny Weekly Reset Scraper
- @author: MadMerlyn
- """
- from urllib.request import urlopen
- import sys
- import re
- from bs4 import BeautifulSoup as web
- ORIGINAL = sys.stdout
- HTML = urlopen('http://www.bungie.net/en/Activities')
- SOUP = web(HTML, 'lxml')
- def div_id(obj, _id):
- """BS4 find 'div' objects of the selected class"""
- result = obj.findAll('div', {'class':_id})
- return result
- def tagwrap(obj, _tag):
- """Wrap 'obj' in html formatted tags of 'Tag'"""
- result = '<{}>'.format(_tag)+obj+'</{}>'.format(_tag)
- return result
- WEEK = SOUP.find('div', {'data-categoryid':'WEEKLY_ACTIVITIES'})
- WEEK_LIST = div_id(WEEK, 'destiny-item-details')
- def mods_list(title, modlist):
- """Create the list of activity modifiers in HTML format"""
- print(' <div class=\"col-sm-6\">', '<br />', sep='\n ')
- print(' ', title, sep='')
- print(' <ul>')
- mods = div_id(modlist, 'standardTitle')
- for item in mods:
- mod = item.get_text()
- burn = re.search('Burn', mod)
- arms = re.search('Specialist|Brawler|Small Arms', mod)
- if burn is True:
- mod = mod+' <span class=\"glyphicon glyphicon-fire\"></span>'
- if arms is True:
- mod = mod+' <span class=\"glyphicon glyphicon-screenshot\"></span>'
- print(' ', tagwrap(mod, 'li'), sep='')
- print(' </ul>')
- print(' </div> <!-- end col-sm-6 -->')
- def nightfall():
- """Get the name of this week's Nightfall"""
- result = WEEK_LIST[0].previous_sibling.previous_sibling.get('style')
- result = re.split(r'pgcrs\/|\.jpg', result)
- result = result[1].replace('strike_', '').replace('_', ' ').title()
- result = tagwrap('Nightfall: '+result, 'h4')
- return result
- def heroic():
- """Get the name of this week's Heroic story"""
- result = div_id(WEEK_LIST[1], 'subtitle')[0].get_text()
- result = result.replace(' Heroic', '')
- result = tagwrap('Weekly Heroic: '+result, 'h4')
- return result
- #Write output to activities.txt
- with open('activities.txt', 'w+') as out_file:
- sys.stdout = out_file
- mods_list(nightfall(), WEEK_LIST[0])
- mods_list(heroic(), WEEK_LIST[1])
- sys.stdout = ORIGINAL
- print(r'Scrape completed! File is located: .\activities.txt')
Add Comment
Please, Sign In to add comment