File: check_scummvm.py

package info (click to toggle)
game-data-packager 73
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 23,420 kB
  • sloc: python: 11,086; sh: 609; makefile: 59
file content (89 lines) | stat: -rwxr-xr-x 2,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2018 Alexandre Detiste <alexandre@detiste.be>
# SPDX-License-Identifier: GPL-2.0-or-later

# Usage:
# curl -s -D headers.html http://wiki.scummvm.org/index.php/Where_to_get_the_games > scummvm.html
# _build/run-tool-uninstalled tools/check_scummvm.py

import os
import re
from bs4 import BeautifulSoup

from game_data_packager.game import load_games

games = {}
print('# Reading data from YAML...')

for name, game in load_games(
    datadir=os.environ.get('GDP_BUILDDIR', 'out')
).items():
    game.load_file_data()
    if game.wikibase != 'http://wiki.scummvm.org/index.php/':
         continue
    assert game.wiki, name

    gog_id = None
    steam_id = None
    for package in game.packages.values():
        gog = package.gog or game.gog
        steam = package.steam or game.steam
        if 'game' in gog:
            gog_id = gog['game']
        elif 'url' in gog:
            gog_id = gog['url']
        if 'id' in steam:
            steam_id = steam['id']

    games[game.wiki] = (gog_id, steam_id)

print('# Reading data from ScummVM wiki...')

# curl -s -D headers.html http://wiki.scummvm.org/index.php/Where_to_get_the_games > scummvm.html

soup = BeautifulSoup(open("scummvm.html"), "html.parser")

downloads = dict()
for table in soup.find_all('table', {'border':'1', 'width':'100%'}):
    print('## ' +table.find_previous('span').text)
    for row in table.find_all('tr'):
        game = None
        for link in row.find_all('a'):
            url = link['href']
            if url == 'http://www.scummvm.org/games/':
                continue
            if 'cdaccess.com/' in url:
                continue

            m = re.search('/index.php/(.*?)$', url)
            if m:
                game = m.group(1)
                downloads.setdefault(game, dict())
                continue

            m = re.search('http://gog.com/game/(.*?)\?pp\=22d200f8670dbdb3e253a90eee5098477c95c23d', url)
            if m:
                downloads[game]['gog'] = m.group(1)
                continue

            m = re.search('http://store.steampowered.com/app/(.*?)$', url)
            if m:
                downloads[game]['steam'] = int(m.group(1))
                continue

            print(game, url)

print('# Join...')
for game, shops in sorted(games.items()):
    shop = shops[0]
    new_shop = downloads.get(game,dict()).get('gog')
    if shop != new_shop:
        print("%-70s" % game, shop, new_shop)

    shop = shops[1]
    new_shop = downloads.get(game,dict()).get('steam')
    if shop != new_shop:
        print("%-70s" % game, shop, new_shop)