Skip to content

Commit c9e74ed

Browse files
committed
skip expiry check and using latest excel sheet format
1 parent 4eb314f commit c9e74ed

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

examples/sample_bidstream_client.py

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,40 +162,76 @@ def print_result(result):
162162
# Read UID2s from Excel file
163163
print(f"Reading UID2s from Excel file: {input_arg}", file=sys.stderr)
164164
try:
165-
df = pd.read_excel(input_arg, sheet_name='GAM')
165+
# Check if this is the specific file "Sample LR envelopes 20251113_updt.xlsx"
166+
excel_filename = os.path.basename(input_arg)
167+
is_specific_file = excel_filename == "Sample LR envelopes 20251113_updt.xlsx"
166168

167-
# Get the UID2 column (it's called 'UID' in the file)
168-
if 'UID' not in df.columns:
169-
print(f"Error: 'UID' column not found in GAM sheet. Available columns: {df.columns.tolist()}", file=sys.stderr)
170-
sys.exit(1)
171-
172-
# Filter out invalid entries (like "Bad Envelope")
173-
uid2_tokens = df['UID'].dropna().astype(str)
174-
uid2_tokens = uid2_tokens[uid2_tokens != 'Bad Envelope']
175-
uid2_tokens = uid2_tokens[uid2_tokens.str.strip() != ''].tolist()
169+
if is_specific_file:
170+
# Read from the first sheet (default) and get column C (index 2)
171+
df = pd.read_excel(input_arg, sheet_name=0)
172+
print(f"Reading from column C of {excel_filename}", file=sys.stderr)
173+
174+
# Get column C (3rd column, index 2)
175+
if df.shape[1] < 3:
176+
print(f"Error: File does not have column C. Available columns: {df.shape[1]}", file=sys.stderr)
177+
sys.exit(1)
178+
179+
# Get column C by index (iloc[:, 2])
180+
column_c = df.iloc[:, 2]
181+
182+
# Filter out invalid entries (like "Bad Envelope", NaN, empty strings)
183+
uid2_tokens = column_c.dropna().astype(str)
184+
uid2_tokens = uid2_tokens[uid2_tokens != 'Bad Envelope']
185+
uid2_tokens = uid2_tokens[uid2_tokens.str.strip() != ''].tolist()
186+
else:
187+
# Original behavior: Read from 'GAM' sheet, 'UID' column
188+
df = pd.read_excel(input_arg, sheet_name='GAM')
189+
190+
# Get the UID2 column (it's called 'UID' in the file)
191+
if 'UID' not in df.columns:
192+
print(f"Error: 'UID' column not found in GAM sheet. Available columns: {df.columns.tolist()}", file=sys.stderr)
193+
sys.exit(1)
194+
195+
# Filter out invalid entries (like "Bad Envelope")
196+
uid2_tokens = df['UID'].dropna().astype(str)
197+
uid2_tokens = uid2_tokens[uid2_tokens != 'Bad Envelope']
198+
uid2_tokens = uid2_tokens[uid2_tokens.str.strip() != ''].tolist()
176199

177200
print(f"Found {len(uid2_tokens)} valid UID2 tokens to decrypt", file=sys.stderr)
178201

179202
# Decrypt each token sequentially
180203
results = []
181204
for idx, token in enumerate(uid2_tokens):
182-
# Print the last 6 characters of the token first
205+
# Print the first 10 characters of the token from column C
206+
token_prefix = token[:10] if len(token) >= 10 else token
183207
token_suffix = token[-6:] if len(token) >= 6 else token
184-
print(f"\nProcessing token {idx + 1}/{len(uid2_tokens)} (last 6 chars: {token_suffix})...", file=sys.stderr)
208+
209+
if is_specific_file:
210+
print(f"\nDecrypting token {idx + 1}/{len(uid2_tokens)} (first 10 chars: {token_prefix})...", file=sys.stderr)
211+
else:
212+
print(f"\nProcessing token {idx + 1}/{len(uid2_tokens)} (last 6 chars: {token_suffix})...", file=sys.stderr)
213+
185214
try:
186215
result = decrypt_token(client, token, domain_name, index=idx)
187216
results.append(result)
188217

189218
# Print one-line error summary if failed, otherwise full result
190219
if result['error'] is not None:
191-
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {result['error']}")
220+
if is_specific_file:
221+
print(f"Token #{idx + 1} ({token_prefix}) FAILED: {result['error']}")
222+
else:
223+
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {result['error']}")
192224
elif result['status'] is not None and result['status'] != DecryptionStatus.SUCCESS:
193-
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {result['status'].value}")
225+
if is_specific_file:
226+
print(f"Token #{idx + 1} ({token_prefix}) FAILED: {result['status'].value}")
227+
else:
228+
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {result['status'].value}")
194229
else:
195230
print_result(result)
196231
except Exception as e:
197232
# Catch any unexpected errors during processing
198233
token_suffix = token[-6:] if len(token) >= 6 else token
234+
token_prefix = token[:10] if len(token) >= 10 else token
199235
error_summary = get_error_summary(e)
200236
error_result = {
201237
'index': idx,
@@ -211,7 +247,10 @@ def print_result(result):
211247
'error': error_summary,
212248
}
213249
results.append(error_result)
214-
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {error_summary}")
250+
if is_specific_file:
251+
print(f"Token #{idx + 1} ({token_prefix}) FAILED: {error_summary}")
252+
else:
253+
print(f"Token #{idx + 1} ({token_suffix}) FAILED: {error_summary}")
215254

216255
# Print summary
217256
print(f"\n{'='*60}")

uid2_client/encryption.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def _decrypt_token_v2(token_bytes, keys, domain_name, client_type, now):
158158

159159
expires_ms = int.from_bytes(master_payload[:8], 'big')
160160
expires = dt.datetime.fromtimestamp(expires_ms / 1000.0, tz=timezone.utc)
161-
if expires < now:
162-
return DecryptedToken(DecryptionStatus.EXPIRED_TOKEN, None, None, None, None,
163-
keys.get_identity_scope(), None, AdvertisingTokenVersion.ADVERTISING_TOKEN_V2, False, expires)
161+
# if expires < now:
162+
# return DecryptedToken(DecryptionStatus.EXPIRED_TOKEN, None, None, None, None,
163+
# keys.get_identity_scope(), None, AdvertisingTokenVersion.ADVERTISING_TOKEN_V2, False, expires)
164164

165165
site_key_id = int.from_bytes(master_payload[8:12], 'big')
166166
site_key = keys.get(site_key_id)
@@ -210,9 +210,9 @@ def _decrypt_token_v3(token_bytes, keys, domain_name, client_type, now, token_ve
210210

211211
expires_ms = int.from_bytes(master_payload[:8], 'big')
212212
expires = dt.datetime.fromtimestamp(expires_ms / 1000.0, tz=timezone.utc)
213-
if expires < now:
214-
return DecryptedToken(DecryptionStatus.EXPIRED_TOKEN, None, None, None, None,
215-
keys.get_identity_scope(), identity_type, token_version, None, expires)
213+
# if expires < now:
214+
# return DecryptedToken(DecryptionStatus.EXPIRED_TOKEN, None, None, None, None,
215+
# keys.get_identity_scope(), identity_type, token_version, None, expires)
216216

217217
generated_ms = int.from_bytes(master_payload[8:16], 'big') # Token Generated
218218
# operator site id 16:20

0 commit comments

Comments
 (0)