Browse Source

So many changes

master
Tom Dickman 7 years ago
parent
commit
fe38e62de6
  1. 1
      .gitignore
  2. 1
      Pipfile
  3. 37
      Pipfile.lock
  4. 5
      README.md
  5. 18
      crypto51attack/app.py
  6. 29
      crypto51attack/libs/cmc.py
  7. 5
      crypto51attack/libs/mtc.py
  8. 6
      crypto51attack/libs/nicehash.py
  9. 14
      crypto51attack/render.py
  10. 25
      dist/style.css
  11. 8
      index.html
  12. 122
      src/index.html

1
.gitignore

@ -1 +1,2 @@
results.json
dist/index.html

1
Pipfile

@ -6,6 +6,7 @@ name = "pypi"
[packages]
requests-html = "*"
requests = "*"
"jinja2" = "*"
[dev-packages]
pytest = "*"

37
Pipfile.lock

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "618160ee1d95f3adee21bdc1adb65c443aec2bb06f1d9abc664d4f58ba66b56e"
"sha256": "ed3b71be0992fd26223efa1416e99535bcb2964878ac78a764fc7e1af41fe7e7"
},
"pipfile-spec": 6,
"requires": {
@ -64,6 +64,14 @@
],
"version": "==2.6"
},
"jinja2": {
"hashes": [
"sha256:74c935a1b8bb9a3947c50a54766a969d4846290e1e788ea44c1392163723c3bd",
"sha256:f84be1bb0040caca4cea721fcbbbbd61f9be9464ca236387158b0feea01914a4"
],
"index": "pypi",
"version": "==2.10"
},
"lxml": {
"hashes": [
"sha256:01c45df6d90497c20aa2a07789a41941f9a1029faa30bf725fc7f6d515b1afe9",
@ -97,6 +105,12 @@
],
"version": "==4.2.1"
},
"markupsafe": {
"hashes": [
"sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665"
],
"version": "==1.0"
},
"parse": {
"hashes": [
"sha256:8048dde3f5ca07ad7ac7350460952d83b63eaacecdac1b37f45fd74870d849d2"
@ -162,24 +176,9 @@
},
"websockets": {
"hashes": [
"sha256:1d8ce82e5a0c7947b204d0b1abe0f66bc247dc5c605aa5a339df7d91012356e5",
"sha256:2de152acdcffd37e05042ff285f8ef25046c005927d3ea78606ed99524135545",
"sha256:4ea90a598b546233a4c61bef98db4171ac30f1302826729af30001ac1f471098",
"sha256:58f891a21d430b837d61686f50d52efebd415164f9626d10b2000e50ab097439",
"sha256:8ae1b897c61f8e4306c9a18c5c4ecb695738bd4824f330cc7aa45caa95d971d8",
"sha256:9242d6df28fe4c3768c4c6f5b6b6acdfaf1cbc272140c40c0b1c755dc5a5a7bc",
"sha256:a21861e60d336d21c6f99958b14b26e977a81eaf8abd5a478e8ee9d091a6cac1",
"sha256:ac76ccd2a5e36c4e980d00042d217635f0f92ef1574d8ca13e81a22add3f801d",
"sha256:b05205ecdf809fd3c20d597912e9a184d382fcff31c81d86499e5c78aa412346",
"sha256:d069ce1bc3af02ad35ee6aef6f82c4b0ce64ea5e3f9585935830cce5c74340bf",
"sha256:d71d1e24deceb18ccea605adef388d9a452b719e09320698e64b522df9029532",
"sha256:da93fe3b9ebbd0425539c818eaf73ac55301a3449eaa9349029b39098216dac3",
"sha256:e0f4f59900820cc97d17cc0e7d6e0fc9c0d4a65e906d4e2c09217f89a34f1d71",
"sha256:e8d9823a0eb52b5a2cc39b44c13bf99644f006778459da1d0175bc5e92fd8112",
"sha256:ed77c1a7779ff4060920470dc303c9dcba88f22ef769e46868e9bb9ea537ce26",
"sha256:fe8c6e72c2eaf4d03b9e0d33d7f9f14b9a84f47252b1d4670b798ade572ea360"
],
"version": "==5.0"
"sha256:a49d315db5a7a19d55422e1678e8a1c3b9661d7296bef3179fa620cf80b12674"
],
"version": "==5.0.1"
}
},
"develop": {

5
README.md

@ -1,4 +1,5 @@
# Notes
http://whattomine.com/coins.json
TODO: Remove cookies from git
* http://whattomine.com/coins.json
* TODO: Remove cookies from git
* Icons: https://github.com/allienworks/cryptocoins

18
crypto51attack/app.py

@ -2,11 +2,14 @@ import json
from crypto51attack.libs.mtc import MTC
from crypto51attack.libs.nicehash import NiceHash
from crypto51attack.libs.cmc import CMC
if __name__ == '__main__':
mtc = MTC()
nh = NiceHash()
cmc = CMC()
listings = cmc.get_listings()
results = []
for coin in mtc.get_coins():
details = mtc.get_details(coin['link'])
@ -18,8 +21,21 @@ if __name__ == '__main__':
data: dict = {}
data.update(coin)
data.update(details)
data['24h_cost'] = cost
listing = listings.get(data['symbol'])
del data['market_cap']
# Skip anything not in cmc for now
# Also skip bitgem since the hash rate appears to be incorrect
if not listing or data['name'] == 'Bitgem':
continue
data['hour_cost'] = '${:,.0f}'.format(cost * listings['BTC']['price'] / 24.0)
data['market_cap'] = '${:,.0f}'.format(listing['market_cap']) if listing['market_cap'] else None
data['rank'] = listing['rank']
data['cmc_slug'] = listing['website_slug']
results.append(data)
# Sort by rank
results = sorted(results, key=lambda k: k['rank'])
with open('results.json', 'w') as f:
json.dump(results, f)

29
crypto51attack/libs/cmc.py

@ -0,0 +1,29 @@
import requests
class CMC:
def get_listings(self):
results = {}
page_size = 100
start = 1
while True:
print(start)
resp = requests.get('https://api.coinmarketcap.com/v2/ticker/?sort=id&start={}'.format(start))
data = resp.json()
# Stop when we hit the end
if data['metadata'].get('error') == 'id not found':
break
for _id, coin in data['data'].items():
results[coin['symbol']] = {
'rank': coin['rank'],
'market_cap': coin['quotes']['USD']['market_cap'],
'price': coin['quotes']['USD']['price'],
'website_slug': coin['website_slug']
}
start += page_size
return results
if __name__ == '__main__':
cmc = CMC()
print(cmc.get_listings())

5
crypto51attack/libs/mtc.py

@ -32,10 +32,11 @@ class MTC:
def get_details(self, link):
resp = self._session.get(link)
html = resp.html
hash_rate = html.find('.stats tr')[2].find('td', first=True).text
hash_rate = self._get_gh_hash_rate(hash_rate)
hash_rate_pretty = html.find('.stats tr')[2].find('td', first=True).text
hash_rate = self._get_gh_hash_rate(hash_rate_pretty)
return {
'market_cap': html.find('.stats tr')[3].find('td', first=True).text,
'hash_rate_pretty': hash_rate_pretty,
'hash_rate': hash_rate,
'algorithm': html.find('.text-primary strong a', first=True).text
}

6
crypto51attack/libs/nicehash.py

@ -47,7 +47,7 @@ class NiceHash:
"""
def __init__(self):
self._session = requests.Session()
self._session.headers.update({'Cookie': '__cfduid=d1f479f91284d18655ebf5ced80fbdbe21527119214; lang=en; PHPSESSID=51b620pl6vgbvkk74hvkdgk0v3; fiat=USD; _device=b3fb70417ae50dc005e08eff58f5068c3879a393'})
self._session.headers.update({'Cookie': '__cfduid=d1f479f91284d18655ebf5ced80fbdbe21527119214; lang=en; fiat=USD; cf_clearance=9755055ce70e02f83ed6b33abfae01c32f00eb2c-1527175191-300; PHPSESSID=9f64fqdb6oh494ft12l7olqt1s; _device=68d0845e3a0d176169b9711b01325a28b36c6086'})
self._buy_info = requests.get('https://api.nicehash.com/api?method=buy.info').json()
def get_cost(self, algorithm, amount):
@ -69,11 +69,11 @@ class NiceHash:
resp = self._session.get('https://www.nicehash.com/siteapi/market/{}/{}/fixed?limit={}'.format(index, country, max_fixed_price)).json()
if resp['fixedPrice'] == 'Not enough hashing power available.':
continue
day_cost_btc += float(resp['fixedPrice']) * max_fixed_price
amount -= max_fixed_price
day_cost_btc += float(resp['fixedPrice'])
else:
day_cost_btc += float(resp['fixedPrice']) * amount
amount -= amount
day_cost_btc += float(resp['fixedPrice'])
if amount <= 0.0:
return day_cost_btc
return None

14
crypto51attack/render.py

@ -0,0 +1,14 @@
import json
from jinja2 import Template
def render(results):
with open('src/index.html', 'r') as f:
template = Template(f.read())
with open('dist/index.html', 'w') as g:
g.write(template.render(results={'coins': results}))
if __name__ == '__main__':
with open('results.json', 'r') as f:
render(json.load(f))

25
dist/style.css

@ -0,0 +1,25 @@
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
.container {
max-width: 960px;
}
.pricing-header {
max-width: 700px;
}
.card-deck .card {
min-width: 220px;
}
.border-top { border-top: 1px solid #e5e5e5; }
.border-bottom { border-bottom: 1px solid #e5e5e5; }
.box-shadow { box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); }

8
index.html

@ -1,8 +0,0 @@
<html lang="en">
<head>
</head>
<body>
<p>Hi</p>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</body>
</html>

122
src/index.html

@ -0,0 +1,122 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Cryptocurrencies that are Vulnerable to a 51% Attack</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
<!-- Coin icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cryptocoins-icons@2.7.0/webfont/cryptocoins-colors.css">
</head>
<body>
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom box-shadow">
<h5 class="my-0 mr-md-auto font-weight-normal">51crypto</h5>
<nav class="my-2 my-md-0 mr-md-3">
<a class="p-2 text-dark" href="#">About</a>
</nav>
</div>
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Vulnerable PoW Coins</h1>
<p class="lead">This is a collection of coins that are vulnerable to a 51% attack + the price to complete it.</p>
</div>
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col">Rank</th>
<th scope="col">Name</th>
<th scope="col">Symbol</th>
<th scope="col">Market Cap</th>
<th scope="col">Algorithm</th>
<th scope="col">Hash Rate</th>
<th scope="col">1h Attack Cost</th>
</tr>
</thead>
<tbody>
{% for coin in results.coins %}
<tr>
<th scope="row">{{ coin.rank }}</th>
<!-- <td><a href="{{ coin.cmc_link }}"><i class="cc {{coin.symbol }}"></i> {{ coin.name }}</a></td> -->
<td><a href="https://www.coinmarketcap.com/currencies/{{ coin.cmc_slug }}">{{ coin.name }}</a></td>
<td>{{ coin.symbol }}</td>
<td>{{ coin.market_cap }}</td>
<td>{{ coin.algorithm }}</td>
<td>{{ coin.hash_rate_pretty }}</td>
<td>{{ coin.hour_cost }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<footer class="pt-4 my-md-5 pt-md-5 border-top">
<div class="row">
<div class="col-12 col-md">
<img class="mb-2" src="https://getbootstrap.com/assets/brand/bootstrap-solid.svg" alt="" width="24" height="24">
<small class="d-block mb-3 text-muted">&copy; 2017-2018</small>
</div>
<div class="col-6 col-md">
<h5>Features</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Cool stuff</a></li>
<li><a class="text-muted" href="#">Random feature</a></li>
<li><a class="text-muted" href="#">Team feature</a></li>
<li><a class="text-muted" href="#">Stuff for developers</a></li>
<li><a class="text-muted" href="#">Another one</a></li>
<li><a class="text-muted" href="#">Last time</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>Resources</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Resource</a></li>
<li><a class="text-muted" href="#">Resource name</a></li>
<li><a class="text-muted" href="#">Another resource</a></li>
<li><a class="text-muted" href="#">Final resource</a></li>
</ul>
</div>
<div class="col-6 col-md">
<h5>About</h5>
<ul class="list-unstyled text-small">
<li><a class="text-muted" href="#">Team</a></li>
<li><a class="text-muted" href="#">Locations</a></li>
<li><a class="text-muted" href="#">Privacy</a></li>
<li><a class="text-muted" href="#">Terms</a></li>
</ul>
</div>
</div>
</footer>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="../../../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
<script src="../../../../assets/js/vendor/popper.min.js"></script>
<script src="../../../../dist/js/bootstrap.min.js"></script>
<script src="../../../../assets/js/vendor/holder.min.js"></script>
<script>
Holder.addTheme('thumb', {
bg: '#55595c',
fg: '#eceeef',
text: 'Thumbnail'
});
</script>
</body>
</html>
Loading…
Cancel
Save