Code Monkey home page Code Monkey logo

Comments (2)

oOosys avatar oOosys commented on June 21, 2024

The issue with github seems to be that for unknown reason the Internet connection gets lost while downloading files larger than 700 kByte up to 1.2 MByte on a slow connection, so it is neither possible to get the master .zip file of the repository nor a release download.

A work around that currently works for me is to use the github api to download the repository one single file after another (assuming they are each smaller then 1.2 MByte) instead of trying to get its entire content as one file as it is also the case when using git clone:

import hashlib, os, requests

githubUser				= "orbitalquark"
githubUserRepo		= "textadept"
userHOMEdir			= os.path.expanduser("~")

githubRepoContentURL	= f"https://api.github.com/repos/{githubUser}/{githubUserRepo}/contents"
baseDownloadDir		= f"{userHOMEdir}/Downloads/githubUser_{githubUser}__Repo_{githubUserRepo}"
os.system(f"mkdir {baseDownloadDir}")

def getAndSaveFilesListedInURLresponse(url): 
	print(f"	===###===###=== {url=}	{baseDownloadDir=} ")
	objURLresponse = requests.get(url)
	lstObjURLjson = objURLresponse.json()
	print(f" {objURLresponse=}	{lstObjURLjson=}")
	print("------------------------------------------")
	for dct in lstObjURLjson:
		print(f"	>>>IF>>> {dct['type']=}:	{dct=}")
		if dct["type"] == "dir":
			newURL = dct["_links"]["self"]
			newDownloadDir = baseDownloadDir+"/"+dct["path"]
			os.system(f"mkdir {newDownloadDir}")
			print(f"	=== >>> {newURL=}	CREATED {newDownloadDir=} recursionCall() ")
			getAndSaveFilesListedInURLresponse(newURL)
			continue
		if dct["type"] == "file":
			downloadURL		= dct["download_url"]
			fileName 			= dct["name"]
			fullPathFileName	= baseDownloadDir+"/"+dct["path"]
			objURLresponse	= requests.get(downloadURL)
			print(f"	type==file size={dct['size']}: {objURLresponse.status_code=} {fileName=} {downloadURL=} {fullPathFileName=}")
			if objURLresponse.status_code == 200:
				#  Save the content to a file
				with open(fullPathFileName, 'wb') as fwb:
					fwb.write(objURLresponse.content)
				print("	got:	"+fullPathFileName)
				# github prepends the file content with fb"blob {fileSize}\x00" before calculating sha1 
				githubSHA1prefix = b"blob " + f"{len(objURLresponse.content)}".encode("utf-8") + b"\x00"
				print("		with sha= " + hashlib.sha1(githubSHA1prefix + objURLresponse.content).hexdigest())
				# print(response.content.decode('utf-8')) # Print without escaping non-printable bytes
			else:
				print(f"	statusCode: "+str(response.status_code)+")	retrieving:	"+fullPathFileName)
			print(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
			
getAndSaveFilesListedInURLresponse(githubRepoContentURL)

def getGithubSHAofFile(fpFName):
	with open(fpFName, 'rb') as frb:
		fileContent = frb.read()
	githubSHA1prefix = b"blob " + f"{len(fileContent)}".encode("utf-8") + b"\x00"
	sha1sum = hashlib.sha1(githubSHA1prefix + fileContent).hexdigest()
	return sha1sum
	""" bash ( next line behaves in dash other way than in bash )
	~ $ f=/full/path/file/name.ext
	~ $ echo -e "blob $(stat -c '%s' $f)\0$(cat $f)" | sha1sum
	"""

"""
f=baseDownloadDir+"/"+".clang-format"
sha1sum = getGithubSHAofFile(f)
print(type(sha1sum), sha1sum)
"""

It would be sure nice to have another repository with resumable downloads, but at the moment the Python script I have put together for this purpose above runs and downloads the repositories on my slow connection. Issue solved?

from textadept.

orbitalquark avatar orbitalquark commented on June 21, 2024

Sorry, I don't know of any mirrors. My ISP blocks access to SourceForge, so I set up a GitHub mirror of a SourceForge project that uses GitHub Actions to pull in new changes every night so I can use that project. Perhaps you could do something similar using another git hosting service. Perhaps your clever workaround is enough though.

I'm going to close this because I'm not going to set up a mirror and GitHub network issues are out of my control.

from textadept.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.