old_contents: # Reimplementation of the Steam Mobile Authentication protocol, as demonstrated
  # by https://github.com/geel9/SteamAuth (MIT-licensed, as is this code).
  
  import base64
  import hashlib
  import hmac
  import time
  
  _time_offset = None # TODO: Align clocks with Valve
  
  def generate_code(secret, timestamp=None):
  	"""Generate a SteamGuard code for a given shared secret
  
  	If timestamp is None, will generate one for the current
  	time; otherwise it should be a Unix time.
  
  	>>> generate_code("HvveV1y11i/lGOqBWdo3a1fU/290", 1516187198)
  	"2K3V8"
  	"""
  	secret = base64.b64decode(secret)
  	if timestamp is None:
  		timestamp = int(time.time())
  	timestamp //= 30 # The code regenerates every half minute
  	timestamp = timestamp.to_bytes(8, "big")
  	hash = hmac.new(secret, timestamp, hashlib.sha1).digest()
  	# The low four bits of the last byte tell us where to grab four bytes from.
  	b = hash[-1] & 15
  	quad = hash[b:b+4]
  	# The code seems to be masked off to 31-bit (??)
  	code = int.from_bytes(quad, "big") & 0x7FFFFFFF
  	alphabet = "23456789BCDFGHJKMNPQRTVWXY"
  	ret = ""
  	for _ in range(5):
  		ret += alphabet[code % 26]
  		code //= 26
  	return ret
  
  def do_code(user):
  	"""Generate an auth code for logins"""
  	print("Stub, unimplemented")
  
  def do_trade(user):
  	"""Accept all pending trades/markets"""
  	print("Stub, unimplemented")
  
  def do_setup(user):
  	"""Set up a new user"""
  	print("Stub, unimplemented")
  
  def usage():
  	print("USAGE: python3 steamguard.py [command] [user]")
  	print("command is one of:")
  	for func in sorted(globals()):
  		if func.startswith("do_"):
  			doc = globals()[func].__doc__.split("\n")[0]
  			print("%-10s %s" % (func[3:], doc))
  	print("user is the name of the Steam account to use - optional if")
  	print("only one account is registered with this app.")
  	return 1
  
  def main(args):
  	func = user = None
  	for arg in args:
  		f = globals().get("do_" + arg)
  		if f:
  			if func: return usage()
  			func = f
  		else:
  			if user: return usage()
  			user = arg
  	if not user:
  		print("TODO: check if there's exactly one user, and if so,")
  		print("default to that user. Not yet implemented.")
  	if not func: func = do_code
  	func(user)
  
  if __name__ == "__main__":
  	import sys
  	sys.exit(main(sys.argv[1:]))
  
new_contents: # Reimplementation of the Steam Mobile Authentication protocol, as demonstrated
  # by https://github.com/geel9/SteamAuth (MIT-licensed, as is this code).
  
  import base64
  import hashlib
  import hmac
  import time
  
  _time_offset = None # TODO: Align clocks with Valve
  
  def timecheck():
  	url = "https://api.steampowered.com/ITwoFactorService/QueryTime/v0001"
  	import requests # ImportError? Install 'requests' using pip or similar.
  	data = requests.post(url, "steamid=0").json()
  	return int(data["response"]["server_time"]) - int(time.time())
  
  def do_timecheck(user):
  	"""Check your clock against Valve's"""
  	offset = timecheck()
  	if offset == 0:
  		print("Your clock is in sync with Valve's (+/- 0.5 sec)")
  	elif -3 < offset < 3:
  		# A tiny offset is unlikely to cause issues. TODO: Figure out
  		# how far out the clocks can be and still not be a problem.
  		print("Your clock is in sync with Valve's (%+d sec)" % offset)
  	else:
  		print("CAUTION: Your clock is %+d sec out of sync" % offset)
  		print("Consider adjusting your clock, or use --time-sync")
  
  def generate_code(secret, timestamp=None):
  	"""Generate a SteamGuard code for a given shared secret
  
  	If timestamp is None, will generate one for the current
  	time; otherwise it should be a Unix time.
  
  	>>> generate_code("HvveV1y11i/lGOqBWdo3a1fU/290", 1516187198)
  	"2K3V8"
  	"""
  	secret = base64.b64decode(secret)
  	if timestamp is None:
  		timestamp = int(time.time())
  	timestamp //= 30 # The code regenerates every half minute
  	timestamp = timestamp.to_bytes(8, "big")
  	hash = hmac.new(secret, timestamp, hashlib.sha1).digest()
  	# The low four bits of the last byte tell us where to grab four bytes from.
  	b = hash[-1] & 15
  	quad = hash[b:b+4]
  	# The code seems to be masked off to 31-bit (??)
  	code = int.from_bytes(quad, "big") & 0x7FFFFFFF
  	alphabet = "23456789BCDFGHJKMNPQRTVWXY"
  	ret = ""
  	for _ in range(5):
  		ret += alphabet[code % 26]
  		code //= 26
  	return ret
  
  def do_code(user):
  	"""Generate an auth code for logins"""
  	print("Stub, unimplemented")
  
  def do_trade(user):
  	"""Accept all pending trades/markets"""
  	print("Stub, unimplemented")
  
  def do_setup(user):
  	"""Set up a new user"""
  	print("Stub, unimplemented")
  
  def usage():
  	print("USAGE: python3 steamguard.py [command] [user]")
  	print("command is one of:")
  	for func in sorted(globals()):
  		if func.startswith("do_"):
  			doc = globals()[func].__doc__.split("\n")[0]
  			print("%-10s %s" % (func[3:], doc))
  	print("user is the name of the Steam account to use - optional if")
  	print("only one account is registered with this app.")
  	return 1
  
  def main(args):
  	func = user = None
  	for arg in args:
  		f = globals().get("do_" + arg)
  		if f:
  			if func: return usage()
  			func = f
  		else:
  			if user: return usage()
  			user = arg
  	if not user:
  		print("TODO: check if there's exactly one user, and if so,")
  		print("default to that user. Not yet implemented.")
  	if not func: func = do_code
  	func(user)
  
  if __name__ == "__main__":
  	import sys
  	sys.exit(main(sys.argv[1:]))
  
subject: Implement a time sync tool