Last active
December 24, 2021 08:32
-
-
Save honux77/f3710f73fab0ae9b88c9d994ccc86ad5 to your computer and use it in GitHub Desktop.
GitHub Oranizations invite member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "66b707db", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Install Package if not install already\n", | |
"# !pip install PyGithub" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "9fa2179d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Write Auth Token Here\n", | |
"token = \"github_auth_token_here\"\n", | |
"# Organization Name here\n", | |
"orgname = \"my-org\"\n", | |
"filename = \"ghid.csv\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "2e4b462e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from github import Github\n", | |
"g = Github(token)\n", | |
"org = g.get_organization(orgname)\n", | |
"s = 0\n", | |
"f = 0\n", | |
"fuser = {}\n", | |
"with open(filename) as text:\n", | |
" usernames = text.read().split()\n", | |
" for uname in usernames:\n", | |
" try:\n", | |
" user = g.get_user(uname) \n", | |
" org.invite_user(user=user)\n", | |
" s += 1\n", | |
" except Exception as e: \n", | |
" print(e)\n", | |
" fuser[user] = str(e)\n", | |
" f += 1\n", | |
"print(\"Send Invitation Done with Success:{} and Fail:{}\".format(s, f))\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "6867dc30", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
octocat | |
honux | |
crong | |
jk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment