Skip to content

Instantly share code, notes, and snippets.

@BenjaminSchaaf
Created January 5, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminSchaaf/e65c9dbccf32d49c23d97d94b61b95da to your computer and use it in GitHub Desktop.
Save BenjaminSchaaf/e65c9dbccf32d49c23d97d94b61b95da to your computer and use it in GitHub Desktop.
Used by ozf to grant players medals after a season has finished
import sys
import requests
GRANT_ITEM_URL = 'http://api.steampowered.com/ITFPromos_440/GrantItem/v0001/'
def main(api_key):
# ======================================================================== #
# Change 'medals/XXXXX' to whatever path to the file containing steam ids
# Change PromoID to the specific promotion id for that
grant_medals('medals/open_1st', 'PromoID', api_key)
grant_medals('medals/open_2nd', 'PromoID', api_key)
grant_medals('medals/open_3rd', 'PromoID', api_key)
grant_medals('medals/open_participant', 'PromoID', api_key)
grant_medals('medals/inter_1st', 'PromoID', api_key)
grant_medals('medals/inter_2nd', 'PromoID', api_key)
grant_medals('medals/inter_3rd', 'PromoID', api_key)
grant_medals('medals/inter_participant', 'PromoID', api_key)
grant_medals('medals/prem_1st', 'PromoID', api_key)
grant_medals('medals/prem_2nd', 'PromoID', api_key)
grant_medals('medals/prem_3rd', 'PromoID', api_key)
grant_medals('medals/prem_participant', 'PromoID', api_key)
# Don't change anything past this point
# ======================================================================== #
def grant_medals(file, promo_id, api_key):
steam_ids = open(file).readlines()
print("Granting {} to:".format(promo_id))
for steam_id in steam_ids:
print(" {} ".format(steam_id), end='')
grant_item(steam_id, promo_id, api_key)
def grant_item(steam_id, promo_id, api_key):
data = {
'SteamID': steam_id,
'PromoID': promo_id,
'Key': api_key,
}
response = requests.post(GRANT_ITEM_URL, data = data)
try:
json = response.json()
except ValueError:
print('[FAIL: request error/not authorized]')
return
if 'result' not in json:
print('[FAIL: response error/invalid promo id]')
return
result = json['result']
if int(result['status']) != 1:
print("[FAIL: {}]".format(result['statusDetail']))
else:
print("[SUCCESS!]")
if __name__ == '__main__':
main(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment