Local & Infura ipfs loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
installation:
sudo chmod 755 ipfsloader.py
sudo mv ipfsloader.py /usr/local/bin