Github API & request use pitfall avoidance

Github API 

https://api.github.com/repos/{owner}/{repo}

For example: https://api.github.com/repos/toddrob99/redball


The json format after the integration of Docker hub API and Github API

{
    "popularity": 53566932,
    "docker_name": "flyway/flyway",
    "url": "https://github.com/flyway/flyway",
    "github_name": "flyway",
    "github_full_name": "flyway/flyway",
    "owner": {
        "login": "flyway",
        "id": 2109532,
        "node_id": "MDEyOk9yZ2FuaXphdGlvbjIxMDk1MzI=",
        "avatar_url": "https://avatars.githubusercontent.com/u/2109532?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/flyway",
        "html_url": "https://github.com/flyway",
        "followers_url": "https://api.github.com/users/flyway/followers",
        "following_url": "https://api.github.com/users/flyway/following{/other_user}",
        "gists_url": "https://api.github.com/users/flyway/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/flyway/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/flyway/subscriptions",
        "organizations_url": "https://api.github.com/users/flyway/orgs",
        "repos_url": "https://api.github.com/users/flyway/repos",
        "events_url": "https://api.github.com/users/flyway/events{/privacy}",
        "received_events_url": "https://api.github.com/users/flyway/received_events",
        "type": "Organization",
        "site_admin": false
    },
    "star": 7202,
    "fork": 1387,
    "language": "Java",
    "license": {
        "key": "apache-2.0",
        "name": "Apache License 2.0",
        "spdx_id": "Apache-2.0",
        "url": "https://api.github.com/licenses/apache-2.0",
        "node_id": "MDc6TGljZW5zZTI="
    },
    "size": 545215,
    "topics": [
        "aurora",
        "continuous-delivery",
        "continuous-deployment",
        "database",
        "database-administration",
        "database-deployment",
        "database-management",
        "database-migrations",
        "db2",
        "devops",
        "flyway",
        "java",
        "java-library",
        "mariadb",
        "mysql",
        "postgresql",
        "redgate",
        "sql",
        "sqlserver"
    ]
}

request request authentication Github 

1. The first pit: must headers=headers, requests.get(dir, headers, timeout=5) alone cannot be authenticated

2. The get request is often stuck, use timeout=5, an error will be reported if it exceeds five seconds, and then the cycle will be repeated after receiving the error

3. The token here uses Personal access tokens (classic)

token="your_token"
headers = {
    "Authorization": f"Bearer {token}",
}


dir_github = f"https://api.github.com/repos/{url}"
fd = requests.get(dir, headers=headers, timeout=5)
data = json.loads(fd.text)

Regular expression matching website information

# 例子
sentence1 = "New Relic Infrastructure Kafka Integration (https://github.com/newrelic/nri-kafka)"
sentence2 = "https://github.com/circleci/rabbitmq-delayed (this image is for internal use)"
sentence3 = "https://github.com/jonas747/yagpdb]/afsd/fas/"

# 匹配结果
result1="https://github.com/newrelic/nri-kafka"
result2="https://github.com/circleci/rabbitmq-delayed"
result3="https://github.com/jonas747/yagpdb"

To get such a result, chatgpt3.5 was not enough after asking for a long time, and I got the correct answer after asking gpt4.0

pattern = r"(https://github.com/[\w-]+/[\w-]+)"

Regex Testing Website

 RegExr: Learn, Build and Test Regular Expressions Test RegEx

Guess you like

Origin blog.csdn.net/qq_44789957/article/details/131096405