coollsd commited on
Commit
a45d567
·
verified ·
1 Parent(s): a57cd04

Update ccc.py

Browse files
Files changed (1) hide show
  1. ccc.py +23 -58
ccc.py CHANGED
@@ -1,8 +1,6 @@
1
  import aiohttp
2
- import time
3
  import asyncio
4
  import random
5
- import multiprocessing
6
  from dateutil import parser
7
  import os
8
  import logging
@@ -14,12 +12,6 @@ discord_webhook_url = os.environ['webhook']
14
  api_batch_url = "https://epic-alligator-77.deno.dev/post"
15
  asset_info_url = "https://economy.roproxy.com/v2/assets/"
16
 
17
- assets_checked = multiprocessing.Value('i', 0)
18
- valid_assets_found = multiprocessing.Value('i', 0)
19
-
20
- last_used_ids = {}
21
- base_ids = {}
22
-
23
  async def send_to_discord(session, asset_id, name, creator_id, creator_name, creator_type, asset_type, created_date):
24
  embed = {
25
  "embeds": [
@@ -54,7 +46,6 @@ async def send_to_discord(session, asset_id, name, creator_id, creator_name, cre
54
  pass
55
 
56
  async def check_asset_batch(session, asset_ids):
57
- global assets_checked, valid_assets_found
58
  payload = [{"assetId": asset_id} for asset_id in asset_ids]
59
 
60
  try:
@@ -78,11 +69,7 @@ async def check_asset_batch(session, asset_ids):
78
  pass
79
 
80
  async def fetch_asset_info(session, asset_id):
81
- global assets_checked, valid_assets_found
82
  try:
83
- with assets_checked.get_lock():
84
- assets_checked.value += 1
85
-
86
  async with session.get(f"{asset_info_url}{asset_id}/details") as asset_info_response:
87
  if asset_info_response.status == 200:
88
  asset_info = await asset_info_response.json()
@@ -95,13 +82,8 @@ async def fetch_asset_info(session, asset_id):
95
  creator_type = creator.get("CreatorType", "Unknown")
96
  created_date_str = asset_info.get("Created", "Unknown")
97
  created_date = parse_iso8601(created_date_str)
98
- if created_date:
99
- created_date_formatted = created_date.strftime("%Y-%m-%d %H:%M:%S")
100
- else:
101
- created_date_formatted = "Unknown"
102
 
103
- with valid_assets_found.get_lock():
104
- valid_assets_found.value += 1
105
  await send_to_discord(session, asset_id, name, creator_id, creator_name, creator_type, asset_type, created_date_formatted)
106
  except (aiohttp.ClientError, asyncio.TimeoutError, ConnectionError):
107
  pass
@@ -112,51 +94,34 @@ def parse_iso8601(date_str):
112
  except ValueError:
113
  return None
114
 
115
- def generate_base_id():
116
- base = random.randint(70000000000000, 140000000000000)
117
- return str(base)
118
-
119
- def initialize_base_ids():
120
- for digit in range(7, 15):
121
- base_ids[digit] = generate_base_id()
122
- last_used_ids[digit] = int(base_ids[digit])
123
-
124
  def generate_ids_batch(digit, batch_size=10000):
125
- last_used_id = last_used_ids[digit]
126
- offset = random.randint(-1000000, 1000000)
127
- ids_batch = [str(last_used_id + offset + i) for i in range(batch_size)]
128
- last_used_ids[digit] += batch_size
129
- return ids_batch
130
-
131
- async def run_scanner_instance(digit):
132
- while True:
133
- try:
134
- async with aiohttp.ClientSession() as session:
135
- batch = generate_ids_batch(digit)
136
- await check_asset_batch(session, batch)
137
- except (aiohttp.ClientError, asyncio.TimeoutError, ConnectionError):
138
- await asyncio.sleep(1) # Add a small delay before retrying
139
 
140
  async def print_status_periodically():
141
  while True:
142
  print("Working")
143
  await asyncio.sleep(60)
144
 
145
- def run_scanner_in_process(digit):
146
- asyncio.run(run_scanner_instance(digit))
147
-
148
- if __name__ == "__main__":
149
- initialize_base_ids()
150
- processes = []
151
- instances_per_digit = 20000
152
-
153
- for i in range(instances_per_digit):
154
  digit = 7 + (i % 8)
155
- process = multiprocessing.Process(target=run_scanner_in_process, args=(digit,))
156
- processes.append(process)
157
- process.start()
158
-
159
- asyncio.run(print_status_periodically())
160
 
161
- for process in processes:
162
- process.join()
 
1
  import aiohttp
 
2
  import asyncio
3
  import random
 
4
  from dateutil import parser
5
  import os
6
  import logging
 
12
  api_batch_url = "https://epic-alligator-77.deno.dev/post"
13
  asset_info_url = "https://economy.roproxy.com/v2/assets/"
14
 
 
 
 
 
 
 
15
  async def send_to_discord(session, asset_id, name, creator_id, creator_name, creator_type, asset_type, created_date):
16
  embed = {
17
  "embeds": [
 
46
  pass
47
 
48
  async def check_asset_batch(session, asset_ids):
 
49
  payload = [{"assetId": asset_id} for asset_id in asset_ids]
50
 
51
  try:
 
69
  pass
70
 
71
  async def fetch_asset_info(session, asset_id):
 
72
  try:
 
 
 
73
  async with session.get(f"{asset_info_url}{asset_id}/details") as asset_info_response:
74
  if asset_info_response.status == 200:
75
  asset_info = await asset_info_response.json()
 
82
  creator_type = creator.get("CreatorType", "Unknown")
83
  created_date_str = asset_info.get("Created", "Unknown")
84
  created_date = parse_iso8601(created_date_str)
85
+ created_date_formatted = created_date.strftime("%Y-%m-%d %H:%M:%S") if created_date else "Unknown"
 
 
 
86
 
 
 
87
  await send_to_discord(session, asset_id, name, creator_id, creator_name, creator_type, asset_type, created_date_formatted)
88
  except (aiohttp.ClientError, asyncio.TimeoutError, ConnectionError):
89
  pass
 
94
  except ValueError:
95
  return None
96
 
 
 
 
 
 
 
 
 
 
97
  def generate_ids_batch(digit, batch_size=10000):
98
+ base = random.randint(70000000000000, 140000000000000)
99
+ for i in range(batch_size):
100
+ yield str(base + i)
101
+
102
+ async def run_scanner_instance(digit, semaphore):
103
+ async with aiohttp.ClientSession() as session:
104
+ while True:
105
+ try:
106
+ async with semaphore:
107
+ batch = list(generate_ids_batch(digit))
108
+ await check_asset_batch(session, batch)
109
+ except (aiohttp.ClientError, asyncio.TimeoutError, ConnectionError):
110
+ await asyncio.sleep(1)
 
111
 
112
  async def print_status_periodically():
113
  while True:
114
  print("Working")
115
  await asyncio.sleep(60)
116
 
117
+ async def main():
118
+ semaphore = asyncio.Semaphore(100) # Limit concurrent tasks
119
+ tasks = []
120
+ for i in range(160000): # 20000 instances per digit * 8 digits
 
 
 
 
 
121
  digit = 7 + (i % 8)
122
+ tasks.append(run_scanner_instance(digit, semaphore))
123
+ tasks.append(print_status_periodically())
124
+ await asyncio.gather(*tasks)
 
 
125
 
126
+ if __name__ == "__main__":
127
+ asyncio.run(main())