Package: hfmirror
hfmirrorMirror for resources to local and huggingface.InstallationYou can simply install it withpipcommand line from the official PyPI site.pipinstallhfmirrorFor more information about installation, you can refer toInstallation.Quick StartMirror Github Releases to Your DiskThe following code can mirror the release files of repositorynarugo1992/gcharto your local directorytest_releasesfromhfmirror.resourceimportGithubReleaseResourcefromhfmirror.storageimportLocalStoragefromhfmirror.syncimportSyncTaskif__name__=='__main__':github=GithubReleaseResource(# the github repositoryrepo='narugo1992/gchar',# access_token of github client (if needed)access_token='my_github_access_token',# add files like LATEST_RELEASE to mark the versionsadd_version_attachment=True,)storage=LocalStorage('test_releases')task=SyncTask(github,storage)task.sync()This is thetest_releasestest_releases
├── LATEST_RELEASE
├── LATEST_RELEASE_0
├── LATEST_RELEASE_0.0
├── LATEST_RELEASE_0.0.1
├── LATEST_RELEASE_0.0.2
├── LATEST_RELEASE_0.0.3
├── LATEST_RELEASE_0.0.4
├── LATEST_RELEASE_0.0.5
├── LATEST_RELEASE_0.0.6
├── LATEST_RELEASE_0.0.8
├── v0.0.1
│   ├── gchar-0.0.1-py3-none-any.whl
│   └── gchar-0.0.1.tar.gz
├── v0.0.2
│   ├── gchar-0.0.2-py3-none-any.whl
│   └── gchar-0.0.2.tar.gz
├── v0.0.3
│   ├── gchar-0.0.3-py3-none-any.whl
│   └── gchar-0.0.3.tar.gz
├── v0.0.4
│   ├── gchar-0.0.4-py3-none-any.whl
│   └── gchar-0.0.4.tar.gz
├── v0.0.5
│   ├── gchar-0.0.5-py3-none-any.whl
│   └── gchar-0.0.5.tar.gz
├── v0.0.6
│   ├── gchar-0.0.6-py3-none-any.whl
│   └── gchar-0.0.6.tar.gz
└── v0.0.8
    ├── gchar-0.0.8-py3-none-any.whl
    └── gchar-0.0.8.tar.gzMirror Game Skins to HuggingFaceYour can mirror the skins of genshin impact based ongcharto huggingface repo, using the following code with custom resource and huggingface repository storage:importmimetypesimportosimportrefromtypingimportIterable,Union,Tuple,Any,Mapping,List,Typefromgchar.games.baseimportCharacterasBaseCharacterfromgchar.games.genshinimportCharacterfromhbutils.systemimporturlsplitfromhuggingface_hubimportHfApifromtqdm.autoimporttqdmfromhfmirror.resourceimportSyncResourcefromhfmirror.resource.resourceimportTargetPathTypefromhfmirror.storageimportHuggingfaceStoragefromhfmirror.syncimportSyncTaskfromhfmirror.utilsimportsrequest,get_requests_sessionclassArknightsSkinResource(SyncResource):def__init__(self,chs:List[Character],ch_type:Type[BaseCharacter]):self.characters=chsself.ch_type=ch_typeself.session=get_requests_session()defgrab(self)->Iterable[Union[Tuple[str,Any,TargetPathType,Mapping],Tuple[str,Any,TargetPathType],]]:yield'metadata',{'game':self.ch_type.__game_name__},''_exist_ids=set()forchintqdm(self.characters):ifch.indexin_exist_ids:continuemetadata={'id':ch.index,'cnname':str(ch.cnname)ifch.cnnameelseNone,'jpname':str(ch.jpname)ifch.jpnameelseNone,'enname':str(ch.enname)ifch.ennameelseNone,'alias':list(map(str,ch.alias_names)),}yield'metadata',metadata,f'{ch.index}'_exist_ids.add(ch.index)forskininch.skins:_,ext=os.path.splitext(urlsplit(skin.url).filename)ifnotext:resp=srequest(self.session,'HEAD',skin.url)ext=mimetypes.guess_extension(resp.headers['Content-Type'])filename=re.sub(r'\W+','_',skin.name).strip('_')+extyield'remote',skin.url,f'{ch.index}/{filename}',{'name':skin.name}if__name__=='__main__':resource=ArknightsSkinResource(Character.all(contains_extra=False),Character)api=HfApi(token=os.environ['HF_TOKEN'])api.create_repo('narugo/test_repo',repo_type='dataset',exist_ok=True)storage=HuggingfaceStorage(repo='narugo/test_repo',hf_client=api,namespace='genshin',)task=SyncTask(resource,storage)task.sync()