Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Script aimed at scraping SHiFT Codes from websites, currently all provided from
- [Borderlands 3](https://mentalmars.com/game-news/borderlands-3-golden-keys/)
- [Borderlands The Pre-Sequel](https://mentalmars.com/game-news/bltps-golden-keys/)
- [Tiny Tina's Wonderlands](https://mentalmars.com/game-news/tiny-tinas-wonderlands-shift-codes)
- [Borderlands 4](https://mentalmars.com/game-news/borderlands-4-shift-codes/)

Instead of publishing this as part of [Fabbi's autoshift](https://github.com/Fabbi/autoshift), this is aimed at publishing a machine readable file that can be hit by autoshift. This reduces the load on mentalmars as it's likely not ok to have swarms of autoshifts scraping their website. Instead codes are published to the repo here:
- https://github.com/ugoogalizer/autoshift-codes
- [https://github.com/DankestMemeLord/autoshift-codes](https://github.com/DankestMemeLord/autoshift-codes)
With a direct link here:
- https://raw.githubusercontent.com/ugoogalizer/autoshift-codes/main/shiftcodes.json
- [https://raw.githubusercontent.com/DankestMemeLord/autoshift-codes/refs/heads/main/shiftcodes.json](https://raw.githubusercontent.com/DankestMemeLord/autoshift-codes/refs/heads/main/shiftcodes.json)


## Intent
Expand Down Expand Up @@ -220,4 +221,4 @@ docker tag ${IMAGE} docker.io/ugoogalizer/autoshift-scraper:${VERSIONTAG}
docker push docker.io/ugoogalizer/autoshift-scraper:latest
docker push docker.io/ugoogalizer/autoshift-scraper:${VERSIONTAG}

```
```
62 changes: 59 additions & 3 deletions autoshift-scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"game": "Borderlands: Game of the Year Edition",
"sourceURL": "https://mentalmars.com/game-news/borderlands-golden-keys/",
"platform_ordered_tables": [
"universal",
"universal",
"universal"
]
},{
"game": "Borderlands 2",
"sourceURL": "https://mentalmars.com/game-news/borderlands-2-golden-keys/",
"platform_ordered_tables": [
"universal",
"universal",
"universal",
"pc",
Expand All @@ -30,12 +32,29 @@
"universal",
"discard"
]
},{
"game": "Borderlands 2",
"sourceURL": "https://mentalmars.com/game-news/borderlands-2-assault-on-dragon-keep-head-skins/",
"platform_ordered_tables": [
"pc",
"xbox",
"Playstation",
"pc",
"xbox",
"Playstation"
]
},{
"game": "Borderlands 2",
"sourceURL": "https://mentalmars.com/game-news/get-borderlands-2-luck-zafords-shift-codes/",
"platform_ordered_tables": [
"universal"
]
},{
"game": "Borderlands 3",
"sourceURL": "https://mentalmars.com/game-news/borderlands-3-golden-keys/",
"platform_ordered_tables": [
"universal",
"discard",
"universal",
"universal",
"universal",
"universal",
Expand All @@ -48,6 +67,7 @@
"game": "Borderlands The Pre-Sequel",
"sourceURL": "https://mentalmars.com/game-news/bltps-golden-keys/",
"platform_ordered_tables": [
"universal",
"universal",
"universal",
"pc",
Expand All @@ -69,19 +89,36 @@
"game": "Tiny Tina's Wonderlands",
"sourceURL": "https://mentalmars.com/game-news/tiny-tinas-wonderlands-shift-codes/",
"platform_ordered_tables": [
"universal",
"universal",
"universal"
]
},{
"game": "Borderlands 4",
"sourceURL": "https://mentalmars.com/game-news/borderlands-4-shift-codes/",
"platform_ordered_tables": [
"universal",
"universal",
"universal",
"discard"
]
}]

def remap_dict_keys(dict_keys):
# List of table headings to be mapped to standard values
# Here in case of variation in table headings
heading_map = {
'Borderlands 4 SHiFT Code': 'code',
'PC SHiFT Code': 'code',
'Xbox SHiFT Code': 'code',
'Playstation SHiFT Code': 'code',
'SHiFT Code': 'code',
'PC SHiFT Code': 'code',
'Luck of the Zafords SHiFT Codes': 'code',
'Expires': 'expires',
'Expiration Date' :'expires',
'Head': 'reward',
'Skin': 'reward',
'Reward': 'reward'
}
return dict((heading_map[key], dict_keys[key]) if key in heading_map else (key, value) for key, value in dict_keys.items())
Expand Down Expand Up @@ -208,6 +245,25 @@ def generateAutoshiftJSON(website_code_tables, previous_codes, include_expired):
if not include_expired and code.get("expired"):
continue

#Skiip code if it isn't 29 characters(standard length)
if len(code.get('code')) != 29:
continue

#Restructure to account for the added special pages
#Zafords Skins
if (code_table.get("sourceURL") == "https://mentalmars.com/game-news/get-borderlands-2-luck-zafords-shift-codes/"):
if code.get("Platform") in {"Xbox 360", "Classic PC", "PlayStation 3"}:
continue
code_table['platform'] = 'universal'
code.pop('Platform', None)
code['reward'] = 'Luck of the Zafords Skins'
if (code.get("code")) == None:
for key in code.keys():
if "SHiFT" in key:
code['code'] = code.pop(key)
break


# Extract out the previous archived date if the key existed previously
archived = getPreviousCodeArchived(code,code_table.get("game"),previous_codes)
if archived == None:
Expand Down Expand Up @@ -258,7 +314,7 @@ def generateAutoshiftJSON(website_code_tables, previous_codes, include_expired):
"version": "0.1",
"description": "GitHub Alternate Source for Shift Codes",
"attribution": "Data provided by https://mentalmars.com",
"permalink": "https://raw.githubusercontent.com/ugoogalizer/autoshift/master/shiftcodes.json",
"permalink": "https://raw.githubusercontent.com/DankestMemeLord/autoshift-codes/refs/heads/main/shiftcodes.json",
"generated": {
"human": generatedDateAndTime
},
Expand Down Expand Up @@ -393,4 +449,4 @@ def main(args):
except (KeyboardInterrupt, SystemExit):
pass

_L.info("Goodbye.")
_L.info("Goodbye.")