Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import ipfsapi
import requests
import random
import string
# Gateways
gateways = [
"rx14.co.uk",
"ipfs.deo.moe",
"hardbin.com",
"gateway.pinata.cloud",
"ipfs.jes.xxx",
"gateway.ipfs.io",
"gateway.originprotocol.com",
"ipfs.greyh.at",
"ipfs.busy.org",
"ipfs.eternum.io",
"gateway.temporal.cloud",
"ipfs.fooock.com",
"cloudflare-ipfs.com",
"siderus.io",
"ipfs.sloppyta.co",
"ipfs.io",
"ipfs.infura.io",
"gateway.serph.network",
"ipfs.wa.hle.rs/ipfs/Qmaisz6NMhDB51cCvNWa1GMS7LU1pAxdF4Ld6Ft9kZEP2a"
]
def main():
# Using my local peer to pin new files
api = ipfsapi.connect('127.0.0.1', 5003)
for i in gateways:
# Create some random seed so I have a different Hash on every request
key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(50))
# Create a new file containing my random seed
with open('index.html', 'a') as the_file:
the_file.write("<html><body><a href=\"https://textile.io\" rel=\"%s\">Textile Photos Rocks!</a></body></html>\n" % key)
# Add the file to my local peer
res = api.add('index.html')
# Timeout code if greater than 60s
time = 101
try:
# Request the new file from our current Gateway
result = requests.get("https://" + i + "/ipfs/" + res['Hash'], timeout=60)
if result.status_code != 200:
# Status code if not 200 response, lazy just throw it in that column
time = result.status_code
else:
time = result.elapsed.total_seconds()
except:
time = 9999
print(i, time, res['Hash'])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.