text: import requests
  import os
  import datetime
  import time
  import pyperclip
  import sys
  import jstris_stats_template
  from urllib import parse
  # 游戏模式 1 = sprint, 3 = cheese, 4 = survival, 5 = ultra, 7 = 20TSD, 8 = PC Mode
  # 行数 1 = 40L/10L, 2 = 20L/18L, 3 = 100L, 4 = 1000L
  
  url = "https://jstris.jezevec10.com/"
  
  
  def main(userName=""):
      copy = True
      output_log = False
      haveSprint40 = False
      haveCheese100 = False
      Cheese100Pieces = 0
      if os.path.isfile('username.txt'):
          with open('username.txt') as usr_name_local:
              userName = usr_name_local.read()
              copy = False
              output_log = True
              if not os.path.isfile('results.txt'):
                  print("已开启记录查询结果 如果不需要请在username.txt前加_")
              elif os.path.isfile('_username.txt'):
                  with open('_username.txt') as usr_name_local:
                      userName = usr_name_local.read()
                      copy = False
                      output_log = False
      elif len(sys.argv) >= 2 and __name__ == "__main__":
          userName = sys.argv[1]
      elif not userName:
          userName = input("UserName(可在当前目录创建username.txt文件写入名字来省略这一步):")
      username_urlencode = parse.quote(userName)
      stats_Sprint40 = search(userName, 1, 1, url)
      stats_Cheese100 = search(userName, 3, 3, url)
      if stats_Sprint40.get("error") is not None and stats_Cheese100.get(
              "error") is not None:
          return {
              "result": "没有在 Jstris 查找到此用户",
              "copy": False,
              "output_log": False,
              "success": False
          }
      if stats_Sprint40.get("min") != 0:
          haveSprint40 = True
      if stats_Cheese100.get("min") != 0:
          haveCheese100 = True
          Cheese100Pieces = search_game(stats_Cheese100["best"][0]["id"],
                                        url)["blocks"]
      result = jstris_stats_template.Template(haveSprint40, haveCheese100).format(
          sprint40_Time=stats_Sprint40.get("min"),
          cheese100_Time=stats_Cheese100.get("min"),
          cheese100_Pieces=Cheese100Pieces,
          url=url,
          username=userName,
          username_urlencode=username_urlencode)
      return {
          "result": result,
          "copy": copy,
          "output_log": output_log,
          "success": True
      }
  
  
  def search(username, game, mode, url):
      stats = requests.get(
          url + ("api/u/{username}/records/{game}?mode={mode}&best"
                 ).format(username=username, game=game, mode=mode)).json()
      return stats
  
  
  def search_game(gameid, url):
      stats = requests.get(url +
                           ("api/record/{gameid}").format(gameid=gameid)).json()
      return stats
  
  
  def log(log_content):
      time_now = datetime.datetime.now()
      with open("results.txt", 'a') as output_log_file:
          output_log_file.write("\n\n{datetime}\n{log_content}".format(
              datetime=time_now.strftime(r'%Y-%m-%d %H:%M'),
              log_content=log_content))
  
  
  if __name__ == "__main__":
      result = main()
      print(result["result"])
      if result["copy"]:
          pyperclip.copy(result["result"])
      if result["output_log"]:
          log(result["result"])
      time.sleep(15)
  