{"id":14065904,"url":"https://github.com/chinanf-boy/explain-starred","last_synced_at":"2026-06-24T02:31:17.274Z","repository":{"id":90548241,"uuid":"111792064","full_name":"chinanf-boy/explain-starred","owner":"chinanf-boy","description":"manager your star ,simple py run, explain to you","archived":false,"fork":false,"pushed_at":"2018-01-05T13:10:54.000Z","size":3,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T18:15:53.551Z","etag":null,"topics":["explain","explain-starred","starred"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chinanf-boy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-11-23T09:52:06.000Z","updated_at":"2022-12-05T01:28:14.000Z","dependencies_parsed_at":"2023-07-21T21:06:19.045Z","dependency_job_id":null,"html_url":"https://github.com/chinanf-boy/explain-starred","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chinanf-boy/explain-starred","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Fexplain-starred","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Fexplain-starred/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Fexplain-starred/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Fexplain-starred/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chinanf-boy","download_url":"https://codeload.github.com/chinanf-boy/explain-starred/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Fexplain-starred/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34714992,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-24T02:00:07.484Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["explain","explain-starred","starred"],"created_at":"2024-08-13T07:04:48.762Z","updated_at":"2026-06-24T02:31:17.256Z","avatar_url":"https://github.com/chinanf-boy.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# starred\n\n[![explain](http://llever.com/explain.svg)](https://github.com/chinanf-boy/Source-Explain)\n\n版本\n\u003e 1.3.1\n\n[中文版](./README.zh.md)\n\n# this is one file\n\n\u003e starred.py\n\n## file head default\n\n``` py\n#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport sys # get the config file\nfrom io import BytesIO\nfrom collections import OrderedDict # \nimport click # cmd options good project\nfrom github3 import GitHub # with github token use your project  \n```\n\n### ``BytesIO``\n\n\u003e ``BytesIO`` read and write ``bytes ``in`` memory``, we create a BytesIO, and then write some bytes\n\n### ``OrderedDict``\n\n\u003e ``Key`` is unordered when using ``dict``. When iterating on ``dict``, we can not determine the order of the ``keys``.\n\n\u003e If you want to keep ``the order of Key``, you can use ``OrderedDict``\n\nOrderedDict example\n\n``` py\nfrom collections import OrderedDict\nd = dict([('a', 1), ('b', 2), ('c', 3)])\n# dict的Key是无序的\n# d =  {'a': 1, 'c': 3, 'b': 2}\nod = OrderedDict([('a', 1), ('b', 2), ('c', 3)])\n# OrderedDict的Key是有序的\n# od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])\n```\n\n## next , use the @click easy control options\n\n``` py\n@click.command() # click init \n@click.option('--username', envvar='USER', help='GitHub username')# github usename ready \n@click.option('--token', envvar='GITHUB_TOKEN', help='GitHub token')# github token ready\n@click.option('--sort',  is_flag=True, help='sort by language') # the star project sort\n@click.option('--repository', default='', help='repository name') # you ready update project repo name\n@click.option('--message', default='update stars', help='commit message') # once time you commit -m \"message\"\n@click.version_option(version='1.3.1', prog_name='starred') # version\n\n```\n\nPlease note ``envvar`` , it will get env\n``` py\nimport os\nos.environ.get('GITHUB_TOKEN')\n```\n\n## main def\n\n``` py\ndef starred(username, token, sort, repository, message):\n# the options is above @click.option s\n```\n\nnext\n``` py\n# show the def desc\n  \"\"\"GitHub starred\n    creating your own Awesome List used GitHub stars!\n    example:\n        starred --username maguowei --sort \u003e README.md\n\"\"\"\n\n```\n\nnext\n``` py\n# \n    if repository:\n        if not token:\n            click.secho('Error: create repository need set --token', fg='red')\n            return\n        # get token ready #        *******************              here\n        file = BytesIO()\n        sys.stdout = file\n    else:\n    \n        file = None\n```\n\nnext\n``` py\ngh = GitHub(token=token) # get github \nstars = gh.starred_by(username) # # get username stars list\nclick.echo(desc) # show the desc\nrepo_dict = {} # ready the define\n```\n\nnext\n``` py\nfor s in stars:\n    language = s.language or 'Others'\n    description = html_escape(s.description).replace('\\n', '') if s.description else ''\n    if language not in repo_dict:\n        repo_dict[language] = []\n    repo_dict[language].append([s.name, s.html_url, description.strip()])\n\n# in the for action\n# repo_dict is get all stars message from username\n```\n\nnext\n``` py\nif sort:\n    repo_dict = OrderedDict(sorted(repo_dict.items(), key=lambda l: l[0]))\n\n# become order dict, we tolk\n```\n\nnext\n``` py\nfor language in repo_dict.keys():\n    data = u'  - [{}](#{})'.format(language, '-'.join(language.lower().split()))\n    click.echo(data)\nclick.echo('')\n# set repo - menu \n\nfor language in repo_dict:\n    click.echo('## {} \\n'.format(language.replace('#', '# #')))\n    for repo in repo_dict[language]:\n        data = u'- [{}]({}) - {}'.format(*repo)\n        click.echo(data)\n    click.echo('')\n\n# set single language with Detail\n\nclick.echo(license_.format(username=username))\n\n# get License \n```\n\n## why use ``click.echo``\n\nRemember the above ``file`` variable ？\n\nnext , show the answer!!;)\n\n``` py\nif file:\n    rep = gh.repository(username, repository)\n    if rep: \n        # down here was update Star list\n        readme = rep.readme()\n        readme.update(message, file.getvalue())\n    else:\n        # down here was the first create repository\n\n        # create repo\n        rep = gh.create_repository(repository, 'A curated list of my GitHub stars!')\n        # create file and git init commit message\n        rep.create_file('README.md', 'starred initial commit', file.getvalue())\n    click.launch(rep.html_url) # open browser to url\n\n```\n\n``` py \nfile = BytesIO()\nsys.stdout = file\n\nclick.echo('something')\n# file.getvalue() # something\n```\n\n# Or\n\n## Go [Answer!!](./BytesIO.py) and Run , then show ``hello world``\n\n---\n\nDone!\n\n# MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinanf-boy%2Fexplain-starred","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinanf-boy%2Fexplain-starred","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinanf-boy%2Fexplain-starred/lists"}