Skip to content

Instantly share code, notes, and snippets.

@YannBouyeron
Last active December 21, 2020 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YannBouyeron/caa3fde7915d43c311f2a79148217fec to your computer and use it in GitHub Desktop.
Save YannBouyeron/caa3fde7915d43c311f2a79148217fec to your computer and use it in GitHub Desktop.
Local & Infura ipfs loader
#!/usr/bin/env python3.6
import ipfshttpclient
import os
import glob
infura = ipfshttpclient.connect('/dns/ipfs.infura.io/tcp/5001/https', chunk_size=20000, session=True)
local = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001/http', chunk_size=20000, session=True)
print("""
Local : 1
Infura: 2
""")
menu = int(input(">>> "))
ppp = input("path: ")
if menu == 1:
client = local
elif menu == 2:
client = infura
d = []
print("\n")
print("Hash load:", "\n")
if os.path.isfile(ppp):
l = client.add(ppp)
print(l)
d.append(l["Hash"])
if os.path.isdir(ppp):
client.add(ppp, recursive=True) # on ajoute le dossier (et ses fichiers)
# on ajoute chaque fichier indépendement pour les lister
os.chdir(ppp)
z = glob.glob("**", recursive=True)
z.sort()
for i in z:
l = client.add(i)
print(l)
d.append(l["Hash"])
q = ''
for i in d:
if menu == 1:
q += """<p></br></p><p align=center>{0}</p><div align=center><a href="http://192.168.43.206:8080/ipfs/{0}"><img src="http://192.168.43.206:8080/ipfs/{0}" width=60%></a></div>""".format(i)
elif menu == 2:
q += """<p></br></p><p align=center>{0}</p><div align=center><a href="https://ipfs.io/ipfs/{0}"><img src="http://192.168.43.206:8080/ipfs/{0}" width=60%></a></div>""".format(i)
l = client.add_str(q)
print("\n", "Lexique link:", "\n")
if menu == 1:
print("""<a href="http://192.168.43.206:8080/ipfs/{0}"></a>""".format(l))
elif menu == 2:
print("""<a href="https://ipfs.io/ipfs/{0}"></a>""".format(l))
print("\n")
@YannBouyeron
Copy link
Author

installation:

sudo chmod 755 ipfsloader.py

sudo mv ipfsloader.py /usr/local/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment