Last active
December 4, 2018 16:43
-
-
Save cjavad/c25e0e304e4b42f1dd7c05c177a30f88 to your computer and use it in GitHub Desktop.
Simple python script, to select a random item from a list of string. In this case a list of steam trade urls. By /u/cjavad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| DEFINE FUNCTIONS HERE | |
| """ | |
| import re | |
| # get steamid of trader | |
| def TradeLink2SteamId(tradeurl): | |
| tradeurl = str(tradeurl) | |
| partnerid = re.search("(=).*?(&)", tradeurl).group().strip("=").strip("&") | |
| steamid = int(partnerid) >> 1 | |
| return "STEAM_0:1:" + str(steamid) | |
| """ | |
| PROGRAM STARTS HERE | |
| """ | |
| # First we will input all of the entries in form of a trade url | |
| ANOTHER_ONE = True | |
| ALL_ENTRIES = [] # List with all the trade urls | |
| while ANOTHER_ONE: | |
| i = str(input("Trade url: ")).lower() | |
| # first check if we're done | |
| if i == "done": # if we're done then we will move on | |
| ANOTHER_ONE = False | |
| continue | |
| else: # else we will add another trade url | |
| ALL_ENTRIES.append(i) # Add the tradeurl once | |
| # now we will import pythons random libary, specificly the choice function but we will also need | |
| # the SystemRandom for cryptographically secure random choices so it's as random as it can get. | |
| from random import SystemRandom # no need to import choice as its in SystemRandom already | |
| # then we will create the SystemRandom Class | |
| secure_random = SystemRandom() | |
| # in the end we will select our winner | |
| WINNER_WINNER_CHICKEN_DINNER = secure_random.choice(ALL_ENTRIES) # note how we use .choice from SystemRandom | |
| # last but not least we will output the winner with the python built-in print function | |
| print(WINNER_WINNER_CHICKEN_DINNER) | |
| print(TradeLink2SteamId(WINNER_WINNER_CHICKEN_DINNER)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment