_prep_buy.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import json
  4. import sys
  5. from pathlib import Path
  6. import requests
  7. API = "http://localhost:5000"
  8. MAFILE = r"c:\Users\Administrator\Desktop\tsi19338.maFile"
  9. MARKET = "https://steamcommunity.com/market/listings/730/G180E208A023004"
  10. OUT = Path(r"d:\code\steam\tljb\_tmp_session.json")
  11. def main() -> int:
  12. r = requests.post(
  13. f"{API}/login",
  14. json={
  15. "Username": "tsi19338",
  16. "Password": "ayx71486",
  17. "MaFilePath": MAFILE,
  18. },
  19. timeout=90,
  20. )
  21. print("login", r.status_code)
  22. r.raise_for_status()
  23. d = r.json()
  24. sess = d["session"]
  25. cookies = {c["name"]: c["value"] for c in d.get("cookies") or []}
  26. sls = cookies.get("steamLoginSecure") or f"{sess['steamId']}%7C%7C{sess['accessToken']}"
  27. sid = cookies.get("sessionid") or sess.get("sessionId")
  28. print("steamId", sess.get("steamId"), "sessionId", sid)
  29. wr = requests.get(
  30. "https://store.steampowered.com/api/getfundwalletinfo/?cc=us&l=english",
  31. headers={"Cookie": f"steamLoginSecure={sls}"},
  32. timeout=20,
  33. )
  34. print("wallet_http", wr.status_code, wr.text[:400])
  35. url = (
  36. MARKET
  37. + "/render/?query=&start=0&count=10&country=US&language=schinese&currency=1"
  38. )
  39. cookie = f"timezoneOffset=28800,0; sessionid={sid}; steamLoginSecure={sls}; bMarketOptOut=1"
  40. rr = requests.get(
  41. url,
  42. headers={"User-Agent": "Mozilla/5.0", "Cookie": cookie, "Referer": MARKET},
  43. timeout=30,
  44. )
  45. print("render", rr.status_code)
  46. page = rr.json()
  47. info = page.get("listinginfo") or {}
  48. print("listing_count", len(info))
  49. rows = []
  50. for lid, L in info.items():
  51. sub = int(L.get("converted_price") or 0)
  52. sf = int(L.get("converted_steam_fee") or 0)
  53. pf = int(L.get("converted_publisher_fee") or 0)
  54. rows.append((str(lid), sub, sf, pf, sub + sf + pf))
  55. rows.sort(key=lambda x: x[4])
  56. print(json.dumps(rows[:5], indent=2, ensure_ascii=False))
  57. OUT.write_text(
  58. json.dumps(
  59. {
  60. "session": sess,
  61. "steamLoginSecure": sls,
  62. "sessionId": sid,
  63. "mafile": MAFILE,
  64. "cheapest": rows[0] if rows else None,
  65. "market": MARKET,
  66. },
  67. ensure_ascii=False,
  68. indent=2,
  69. ),
  70. encoding="utf-8",
  71. )
  72. print("saved", OUT)
  73. return 0
  74. if __name__ == "__main__":
  75. try:
  76. sys.stdout.reconfigure(encoding="utf-8")
  77. except Exception:
  78. pass
  79. raise SystemExit(main())