如何以编程方式确定GitHub帐户是否使用默认配置文件图片(化身)?
当GitHub用户注册帐户时,GitHub会提供一个默认的配置文件图片,如下所示: 用户可以根据说明设置自定义配置文件图片 我可以想到的方法是从GitHub用户下载当前的配置文件图片,然后从下载他的默认配置文件图片。然后比较这两张图片。但这个解决方案并不漂亮 是否有一种很好的方法来确定GitHub用户是使用默认配置文件图片还是设置了自定义配置文件图片?我可以检查布尔值之类的。谢谢。GitHub将使用以获取与GitHub用户电子邮件帐户关联的图像 你可以通过电话。如果没有,则表示将使用默认的自动生成图像 如果没有与电子邮件关联的图片,GitHub将使用基于电子邮件哈希生成几何图案:如何以编程方式确定GitHub帐户是否使用默认配置文件图片(化身)?,github,github-api,Github,Github Api,当GitHub用户注册帐户时,GitHub会提供一个默认的配置文件图片,如下所示: 用户可以根据说明设置自定义配置文件图片 我可以想到的方法是从GitHub用户下载当前的配置文件图片,然后从下载他的默认配置文件图片。然后比较这两张图片。但这个解决方案并不漂亮 是否有一种很好的方法来确定GitHub用户是使用默认配置文件图片还是设置了自定义配置文件图片?我可以检查布尔值之类的。谢谢。GitHub将使用以获取与GitHub用户电子邮件帐户关联的图像 你可以通过电话。如果没有,则表示将使用默认的自动
我需要这样做,我认为作为一个生成的图像,像素将被清晰地着色,没有抖动
import requests
from PIL import Image
# image_url = "https://avatars.githubusercontent.com/u/85327959" # a photograph
image_url = "https://avatars.githubusercontent.com/u/85325807?v=4" # a gravatar
img_data = requests.get(image_url).content
with open("avatar.jpg", "wb") as handler:
handler.write(img_data)
image = Image.open("avatar.jpg")
colour_count = len(set(image.getdata()))
print(image.size, "colours:", colour_count)
if colour_count < 10:
print("this is a gravatar")
或
我是怎么用的
在第一年的课程中,我想检查用户是否更新了他们的照片,以便指导团队能够轻松地将回购协议与人匹配
def has_real_photo(repo_path):
repo = git.cmd.Git(repo_path)
origin_url = get_origin_url(repo)
owner = origin_url.split("/")[3]
image_url = f"https://github.com/{owner}.png?size=40"
img_data = requests.get(image_url).content
with open("avatar.jpg", "wb") as handler:
handler.write(img_data)
image = Image.open("avatar.jpg")
colour_count = len(set(image.getdata()))
if colour_count > 10:
block_image = blocky_photo(image)
print(block_image)
return True
else:
block_image = blocky_photo(image)
print(
f"Your GitHub profile picture only has {colour_count} colours.\n"
"This makes me think it's the default avatar.\n"
"Not like this:\n",
block_image,
"""Like this:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O │ │
│<│ v │>│
│ \ ─── / │
│ \____/ │
╰───────────╯\n"""
"Go to https://github.com/settings/profile and upload a photo of your face.\n"
"This really helps us understand who's who and be more useful in tutorials.",
)
return False
def blocky_photo(image):
colour_map_list = list(
zip(
list(set(image.getdata())),
["█", "░", "▒", "▓", "X", "#", "%", "/", ":", "*"],
)
)
colour_map = {x[0]: x[1] for x in colour_map_list}
image = image.resize((20, 10), Image.NEAREST)
pixels = list(image.getdata())
width, height = image.size
block_image = ""
for i in range(len(pixels)):
block_image += colour_map[pixels[i]]
if (i + 1) % (width) == 0:
block_image += "\n "
return block_image
def有真实照片(回购路径):
repo=git.cmd.git(repo\u路径)
来源地址=获取来源地址(repo)
owner=origin\u url.split(“/”[3]
图像_url=f“https://github.com/{owner}.png?大小=40“
img\u data=requests.get(image\u url).content
以open(“avatar.jpg”、“wb”)作为处理程序:
handler.write(img_数据)
image=image.open(“avatar.jpg”)
color\u count=len(设置(image.getdata())
如果颜色计数>10:
block_image=blocky_照片(图像)
打印(块图像)
返回真值
其他:
block_image=blocky_照片(图像)
印刷品(
f“您的GitHub配置文件图片只有{color\u count}种颜色。\n”
“这让我觉得它是默认的化身。\n”
“不是这样:\n”,
块图像,
”“像这样:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O│ │
││
│ \ ─── / │
│ \____/ │
╰───────────╯\n“
“去https://github.com/settings/profile 并上传您的面部照片。\n“
“这确实有助于我们了解谁是谁,并在教程中更有用。”,
)
返回错误
def blocky_照片(图像):
颜色\地图\列表=列表(
拉链(
列表(set(image.getdata()),
["█", "░", "▒", "▓", "X“,”#“,“%”,“/”,“:”,“*”],
)
)
颜色映射={x[0]:x[1]表示颜色映射列表中的x}
image=image.resize((20,10),image.NEAREST)
像素=列表(image.getdata())
宽度,高度=image.size
block_image=“”
对于范围内的i(len(像素)):
块图像+=彩色贴图[像素[i]]
如果(i+1)%(宽度)==0:
块\u图像+=“\n”
返回块图像
他们有一组自己运行的测试,这些测试将打印:
Your GitHub profile picture only has 2 colours.
This makes me think it's the default avatar.
Not like this:
████████████████████
█████░░░░░░░░░░█████
█████░░░░░░░░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
██░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░██
██░░░░░░████░░░░░░██
████████████████████
Like this:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O │ │
│<│ v │>│
│ \ ─── / │
│ \____/ │
╰───────────╯
Go to https://github.com/settings/profile and upload a photo of your face.
This really helps us understand who's who and be more useful in tutorials.
✘ You've got a photo for your GitHub account
您的GitHub个人资料图片只有两种颜色。
这让我觉得它是默认的化身。
不是这样的:
████████████████████
█████░░░░░░░░░░█████
█████░░░░░░░░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
██░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░██
██░░░░░░████░░░░░░██
████████████████████
这样地:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O│ │
││
│ \ ─── / │
│ \____/ │
╰───────────╯
去https://github.com/settings/profile 上传一张你的照片。
这确实有助于我们理解谁是谁,并且在教程中更有用。
✘ 您已经为您的GitHub帐户准备了一张照片
谢谢您的回复。但是我还是没有说清楚。谢谢你的回复。但我还是不太清楚。以这个用户为例:,如何知道它使用了自定义的化身?注意:我不知道他的电子邮件是否被隐藏了。我只知道他的用户名。@hsluoyz你知道他的电子邮件,它不是隐藏的。拿他的任何一个repos:,获得他的主分支的提交(无需克隆,使用,如中所示),您将收到他的电子邮件。campbell@runbox.no"是05B6D7CC7C662BF81E01B3954F88A49。然后我使用此链接获得了配置文件图片:。但它似乎不正确。@hsluoyz这意味着阿拉斯泰尔与它无关。它的几何图案(由GitHub使用)将是:P.S。该面是从这里开始的:
def has_real_photo(repo_path):
repo = git.cmd.Git(repo_path)
origin_url = get_origin_url(repo)
owner = origin_url.split("/")[3]
image_url = f"https://github.com/{owner}.png?size=40"
img_data = requests.get(image_url).content
with open("avatar.jpg", "wb") as handler:
handler.write(img_data)
image = Image.open("avatar.jpg")
colour_count = len(set(image.getdata()))
if colour_count > 10:
block_image = blocky_photo(image)
print(block_image)
return True
else:
block_image = blocky_photo(image)
print(
f"Your GitHub profile picture only has {colour_count} colours.\n"
"This makes me think it's the default avatar.\n"
"Not like this:\n",
block_image,
"""Like this:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O │ │
│<│ v │>│
│ \ ─── / │
│ \____/ │
╰───────────╯\n"""
"Go to https://github.com/settings/profile and upload a photo of your face.\n"
"This really helps us understand who's who and be more useful in tutorials.",
)
return False
def blocky_photo(image):
colour_map_list = list(
zip(
list(set(image.getdata())),
["█", "░", "▒", "▓", "X", "#", "%", "/", ":", "*"],
)
)
colour_map = {x[0]: x[1] for x in colour_map_list}
image = image.resize((20, 10), Image.NEAREST)
pixels = list(image.getdata())
width, height = image.size
block_image = ""
for i in range(len(pixels)):
block_image += colour_map[pixels[i]]
if (i + 1) % (width) == 0:
block_image += "\n "
return block_image
Your GitHub profile picture only has 2 colours.
This makes me think it's the default avatar.
Not like this:
████████████████████
█████░░░░░░░░░░█████
█████░░░░░░░░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
█████░░░████░░░█████
██░░░░░░░░░░░░░░░░██
██░░░░░░░░░░░░░░░░██
██░░░░░░████░░░░░░██
████████████████████
Like this:
╭───────────╮
│ !!!!!!! │
│ / \ │
│ │ O O │ │
│<│ v │>│
│ \ ─── / │
│ \____/ │
╰───────────╯
Go to https://github.com/settings/profile and upload a photo of your face.
This really helps us understand who's who and be more useful in tutorials.
✘ You've got a photo for your GitHub account