Skip to content

Instantly share code, notes, and snippets.

@schrobby
Last active May 19, 2023 19:02
Show Gist options
  • Save schrobby/ee7f8dc6bf6cdeae659e077a81708302 to your computer and use it in GitHub Desktop.
Save schrobby/ee7f8dc6bf6cdeae659e077a81708302 to your computer and use it in GitHub Desktop.
Query w3w for possible mystery clues. 1) Edit wordlist.txt 2) Run w3w.py with your API key (generates w3w.json) 3) Run w3w-to-csv.py (generates w3w.csv)
#!/usr/bin/env python
# Make sure to run w3w.py <words_file> first to generate a JSON file.
from flatten_dict import flatten
import json
import csv
def strip_first_key(nested_dict):
out = []
for key, value in nested_dict.items():
if isinstance(value, dict):
out.append(value)
return out
with open('w3w.json', 'r') as file:
data = json.load(file)
# strip data of top-level keys
stripped_data = strip_first_key(data)
# flatten into a list
flattened_data = [flatten(x, reducer='underscore') for x in stripped_data]
column_keys = flattened_data[0].keys()
with open('w3w.csv', 'w', newline='') as file:
writer = csv.DictWriter(file, fieldnames=column_keys)
writer.writeheader()
writer.writerows(flattened_data)
#!/usr/bin/env python
import requests
import time
import json
import sys
from itertools import permutations
api_key = 'API-KEY'
with open(sys.argv[1] if len(sys.argv) > 1 else 'wordlist.txt', 'r') as file:
words = file.readline().split(',')
words = [word.strip().lower() for word in words]
permutations_list = ['.'.join(permutation) for permutation in permutations(words, 3)]
result_dict = {}
print('Using words: %s' % ', '.join(words))
print(f'Running through {len(permutations_list)} possible permutations:')
for item in permutations_list:
url = f'https://api.what3words.com/v3/convert-to-coordinates?words={item}&key={api_key}'
response = requests.get(url)
if response.status_code == 200:
data = response.json()
result_dict[item] = data
print(item)
else:
print(f'Error occurred for {item}. Status code: {response.status_code}')
time.sleep(0.1)
with open('w3w.json', 'w') as json_file:
json.dump(result_dict, json_file)
print('Result saved in w3w.json')
Washed, Frost, Robot, Misfits, Shady, Goat, Rocked, Lives, Handy, Chest, Dawn, Turkey, Diet, Parrot, Chickens, Locker, Cannonball
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment