You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

88 lines
2.0 KiB

"""
Skript för att söka i FB-läckan.
"""
import re
from termcolor import cprint
import dbViaSSH
def search(db, attribute, value):
"""
Search for attribute in db.
Returns list of matching documents.
"""
if "%" in value or "_" in value:
match = "like"
else:
match = "=="
cursor = db.aql.execute(
f"""
FOR doc IN leak
FILTER doc.@attribute {match} @value
RETURN doc
""",
bind_vars={"attribute": attribute, "value": value},
)
return [doc for doc in cursor]
db = dbViaSSH.db_over_tunnel("Leak")
cprint("\n\nVad vill du söka efter?", attrs=["bold"])
print("1 - Telefonnummer")
print("2 - Facebook-ID")
print("3 - Namn")
print("4 - Arbete")
print("5 - Bostadsort")
print("6 - Födelseort")
print("7 - Epost")
# Få input för attribut
attribute = input("\n>>> ")
attributes = {
"1": ("telefonnummer", "phone"),
"2": ("Facebook-ID", "_key"),
"3": ("namn", "full_name"),
"4": ("arbete", "work"),
"5": ("bostadsort", "lives_in"),
"6": ("födelseort", "from"),
"7": ("epost", "email"),
}
# Bestäm n- eller t-form och få input för värde.
if attribute in ["5", "6", "7"]:
genus = "n"
else:
genus = "t"
cprint(f"\nVilke{genus} {attributes[attribute][0]}? ", attrs=["bold"])
cprint(
"Använd % för att ersätta flera okända tecken, _ för att ersätta ett.",
attrs=["dark"],
)
value = input("\n>>> ")
if attribute == "1": # telefonnummer
value = "".join(re.findall(r"\d+", value))
if value[0] == "0":
value = f"46{value[1:]}"
elif attribute == "3": # namn
value = value.upper()
# Sök i databasen.
result = search(db, attributes[attribute][1], value)
# Presentera reultaten #TODO hur vill man få dem? Spara ner?
for i in result:
print("\n", i["full_name"])
for key, value in i.items():
print(f"{key}: {value}")
print(f'https://facebook.com/{i["_key"]}')
print(f"\nAntal träffar: {len(result)}\n")
dbViaSSH.stop_server()