Add reverse search (#40) #54

Open
brickedsalamander wants to merge 2 commits from brickedsalamander/iseeyour.cash:reverse-search into main
  1. 37
      iseeyourcash.py
  2. 69
      templates/user.html
  3. 12
      utils.py

@ -78,11 +78,42 @@ async def user(request, username=None):
invalid = re.compile("[^A-Za-z0-9_\-\.]")
username = re.sub(r"(?:(?:/)?\bu)?/|@|\s", "", username)
if invalid.findall(username):
return html(template.render(quote=quote, addresses={"btc":-1,"eth":-1,"nano":-1}, totals={"btc":-1,"eth":-1,"nano":-1}, user=username))
return html(template.render(quote=quote, addresses={"btc":-1,"eth":-1,"nano":-1}, totals={"btc":-1,"eth":-1,"nano":-1}, user=username, address=-1))
prices, dt = await utils.get_price()
if dt < datetime.now()-timedelta(hours=1):
await utils.update_price()
addr_patterns = {
"btc": re.compile(r"^[bc1|13][a-zA-HJ-NP-Z0-9]{25,43}$"),
"eth": re.compile(r"^(0x[a-fA-F0-9]{40})$"),
"nano": re.compile(r"^(nano_[13][1-9a-z]{59})$")
}
xmr_pattern = re.compile(r"^[48][0-9AB][1-9A-HJ-NP-Za-km-z]{93}$")
addr_matches = {currency: addr_patterns[currency].match(username) for currency in addr_patterns}
if xmr_pattern.match(username) and not any(list(addr_matches.values())):
# if the address only matches the Monero address pattern
return html(template.render(quote=quote, address=username, user=-2))
elif any(list(addr_matches.values())):
address = username
username = await utils.get_address_data(address)
if username == -1:
addresses = {currency: [] for currency in ("btc", "eth", "nano")}
totals = {currency: 0.0 for currency in ("btc", "eth", "nano")}
# get all information about the address (it may be on multiple blockchains)
for currency in ("btc", "eth", "nano"):
if addr_matches[currency]:
balance = await utils.check_balance(address, currency)
addresses[currency].append([address, None, balance])
totals[currency] += balance * float(prices[currency])
total_float = sum(totals[currency]*float(prices[currency]) for currency in ("btc", "eth", "nano"))
total_usd = f"{total_float:,.2f}"
totals = {currency: [totals[currency], f"{totals[currency]:,.{digits}f}".rstrip("0").rstrip(".")] for currency, digits in (("btc", 8), ("eth", 12), ("nano", 12))}
return html(template.render(quote=quote, addresses=addresses, totals=totals, total_usd=total_usd, user=-1, address=address))
# else the username is known and all addresses of the user should show up.
else:
# if no address hide this info in the user page
address = -1
addresses = await utils.get_user_data(username)
@ -93,7 +124,7 @@ async def user(request, username=None):
}
if addresses["btc"] == -2:
return html(template.render(quote=quote, addresses={"btc":-2,"eth":-2,"nano":-2}, totals={"btc":-2,"eth":-2,"nano":-2}, user=username))
return html(template.render(quote=quote, addresses={"btc":-2,"eth":-2,"nano":-2}, totals={"btc":-2,"eth":-2,"nano":-2}, user=username, address=address))
# add up totals and format the balances
@ -115,7 +146,7 @@ async def user(request, username=None):
return html(template.render(quote=quote, addresses=addresses,
totals=totals, total_usd=total_usd,
user=username))
user=username, address=address))
@app.route("/ranking", name="ranking")
async def ranking(request):

@ -14,11 +14,27 @@
</div>
</div>
{% if address != -1 and user not in [-2, -1] %}
<div class="addressAttribution">
The address {{address}} is owned by user {{user}}.
</div>
{% elif user == -2 %}
<div class="addressAttribution">
The address {{address}} is a Monero address.
</div>
{% endif %}
<div class="logo">
I See Your<span class="yellow"> Cash</span>, {{user}}
{% if user == -2 %}
Nice try, but nobody can see the <span class="yellow">Cash</span> of a Monero address.
{% elif user == -1 %}
I See The <span class="yellow">Cash</span> Of Address</br>{{address}}</br>but i don't know whose it is.
{% else %}
I See Your <span class="yellow">Cash</span>, {{user}}
{% endif %}
</div>
{% if user != -2 %}
<div class="totalBalanceContainer">
{% if addresses["btc"] == -1 %}
<h4 class="subtitle btc">
@ -50,14 +66,18 @@
{% endif %}
{% if total_usd != '0.00' %}
=
<span class="tag is-grey is-large">${{total_usd}}</span>
{% endif %}
<span class="tag is-grey is-large">${{total_usd}}</span>
</div>
<div class="addressesContainer">
{% if addresses["btc"]|length > 0 %}
<p class="addressesTitle">Bitcoin addresses found for {{user}}:</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">Bitcoin addresses found for {{user}}:</p>
{% else %}
<p class="addressesTitle">This address on the Bitcoin blockchain.</p>
{% endif %}
<ul>
{% for address in addresses["btc"] %}
@ -66,7 +86,7 @@
<a target="_blank" href="{{address[5]}}">
<i style="color:rgb(219, 110, 21);" class="fab fa-reddit"></i>
</a>
{% else %}
{% elif address[4] == "twitter" %}
<a target="_blank" href="https://nt.r3d.red{{address[5]}}">
<i style="color:rgb(70, 148, 172);" class="fab fa-twitter"></i>
</a>
@ -78,13 +98,21 @@
{%endfor%}
</ul>
{% else %}
<p class="addressesTitle">No Bitcoin addresses found for this user.</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">No Bitcoin addresses found for this user.</p>
{% else %}
<p class="addressesTitle">This address is not a Bitcoin address.</p>
{% endif %}
{% endif %}
</div>
<div class="addressesContainer">
{% if addresses["nano"]|length > 0 %}
<p class="addressesTitle">Nano addresses found for {{user}}:</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">Nano addresses found for {{user}}:</p>
{% else %}
<p class="addressesTitle">This address on the Nano blockchain.</p>
{% endif %}
<ul>
{% for address in addresses["nano"] %}
@ -93,7 +121,7 @@
<a target="_blank" href="{{address[5]}}">
<i style="color:rgb(219, 110, 21);" class="fab fa-reddit"></i>
</a>
{% else %}
{% elif address[4] == "twitter" %}
<a target="_blank" href="https://nt.r3d.red{{address[5]}}">
<i style="color:rgb(70, 148, 172);" class="fab fa-twitter"></i>
</a>
@ -105,14 +133,22 @@
{%endfor%}
</ul>
{% else %}
<p class="addressesTitle">No Nano addresses found for this user.</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">No Nano addresses found for this user.</p>
{% else %}
<p class="addressesTitle">This address is not a Nano address.</p>
{% endif %}
{% endif %}
</div>
<div class="addressesContainer">
{% if addresses["eth"]|length > 0 %}
<p class="addressesTitle">Ethereum addresses found for {{user}}:</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">Ethereum addresses found for {{user}}:</p>
{% else %}
<p class="addressesTitle">This address on the Ethereum blockchain.</p>
{% endif %}
<ul>
{% for address in addresses["eth"] %}
@ -121,7 +157,7 @@
<a target="_blank" href="{{address[5]}}">
<i style="color:rgb(219, 110, 21);" class="fab fa-reddit"></i>
</a>
{% else %}
{% elif address[4] == "twitter" %}
<a target="_blank" href="https://nt.r3d.red{{address[5]}}">
<i style="color:rgb(70, 148, 172);" class="fab fa-twitter"></i>
</a>
@ -133,11 +169,16 @@
{%endfor%}
</ul>
{% else %}
<p class="addressesTitle">No Ethereum addresses found for this user.</p>
{% if user not in [-2, -1] %}
<p class="addressesTitle">No Ethereum addresses found for this user.</p>
{% else %}
<p class="addressesTitle">This address is not an Ethereum address.</p>
{% endif %}
{% endif %}
{% endif %}
</div>
{% endif %}
<style>
@ -149,6 +190,10 @@
height: 3em !important;
}
.addressAttribution {
text-align: center;
}
.logo {
font-size: 2rem;
font-weight:bold;

@ -499,3 +499,15 @@ async def get_global_stats():
tot_user_count = await conn.execute(text("SELECT COUNT(*) FROM user"))
tot_user_count = tot_user_count.first()[0]
return tot_addr_count, tot_user_count
async def get_address_data(address):
engine = create_async_engine(f"mysql+aiomysql://root:{data['db-password']}@{data['db-name']}:3307/iseeyourcash?charset=utf8mb4")
async with engine.begin() as conn:
username = await conn.execute(text("SELECT U.username FROM address AS A JOIN user AS U ON A.user=U.user_id WHERE A.address_id=:address"),
[{"address": address}])
username = username.first()
print(username)
if username is None:
return -1
return username[0]

Loading…
Cancel
Save