Browse Source

Scraper for steam games

Closes #17
master
Chris Smith 14 years ago
parent
commit
1ca38b7b17
2 changed files with 20 additions and 0 deletions
  1. 18
    0
      src/Scraper.py
  2. 2
    0
      src/helloworld.py

+ 18
- 0
src/Scraper.py View File

@@ -44,4 +44,22 @@ class Scraper:
44 44
         except urllib2.URLError, e:
45 45
           handleError(e)
46 46
 
47
+        return results
48
+
49
+    @staticmethod
50
+    def scrape_steam_game(credentials, base_url):
51
+        results = []
52
+        url = (base_url % credentials) + "?xml=1"
53
+
54
+        try:
55
+          result = urllib2.urlopen(url).read()
56
+          soup = BeautifulSoup(result)
57
+          for ach in soup.findAll('achievement', {'closed': '1'}):
58
+              results.append({'img': ach.find('iconclosed').string.strip(),
59
+                              'title': ach.find('name').string.strip(),
60
+                              'desc': ach.find('description').string.strip(),
61
+                              'date': None})
62
+        except urllib2.URLError, e:
63
+          handleError(e)
64
+
47 65
         return results

+ 2
- 0
src/helloworld.py View File

@@ -88,6 +88,8 @@ class UpdatePage(webapp.RequestHandler):
88 88
             UpdatePage.merge_achievements(account, Scraper.scrape_spore(account.credentials))
89 89
         elif account.source.name == 'Steam':
90 90
             UpdatePage.merge_sources(account, Scraper.scrape_steam(account.credentials))
91
+        elif account.source.created_by != None and account.source.created_by.name == 'Steam':
92
+            UpdatePage.merge_achievements(account, Scraper.scrape_steam_game(account.credentials, account.source.url))
91 93
 
92 94
         self.redirect('/')
93 95
 

Loading…
Cancel
Save