Skip to content

Commit 6a040b5

Browse files
committed
naming cats and amputating them
1 parent d7dd41e commit 6a040b5

File tree

8 files changed

+553
-0
lines changed

8 files changed

+553
-0
lines changed

daizy.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def get_cans():
2+
cans = []
3+
4+
input_total_cans = int(input("How many cans do you have? "))
5+
for can in range(input_total_cans):
6+
input_can_name = input("What is the name of the can? ")
7+
cans.append(input_can_name)
8+
9+
for count, can in enumerate(cans):
10+
print(count+1, can)
11+
12+
input_get_can = int(input("Which can do you want to get? "))-1
13+
print("You got", cans[input_get_can])
14+
15+
# cans = input("name 5 cans in your cupboard:")
16+
17+
18+
# get_cans()
19+
20+
def cat(legs, name):
21+
legs = legs-1
22+
return name + " has " + str(legs) + " legs"
23+
return f"{name} has {legs} legs"
24+
#
25+
# house_of_cats = [
26+
# [4, "Garfield"],
27+
# [5, "Tom"],
28+
# [3, "Puss in Boots"],
29+
# [5, "Socks"],
30+
# ]
31+
# for this_cat in house_of_cats:
32+
# print(cat(this_cat[0], this_cat[1]))
33+
34+
legs = input("How many legs does your cat have? ")
35+
name = input("What is its name? ")
36+
print(cat(int(legs), name))
37+
lopped_cat = cat(int(legs), name)
38+
print(lopped_cat/2)

ghobnc.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import config
2+
from github import Github
3+
4+
gh = Github(config.github_access_key)
5+
6+
7+
def get_orgs():
8+
orgs = []
9+
for org in gh.get_user().get_orgs():
10+
orgs.append(org.login)
11+
return orgs
12+
13+
14+
def get_repos_default_branch(org):
15+
repos = []
16+
for repo in gh.get_organization(org).get_repos():
17+
repos.append([org, repo.name, repo.default_branch])
18+
return repos
19+
20+
21+
def filtered_repos(run_orgs, old_branch):
22+
repos = []
23+
for org in run_orgs:
24+
org_repos = get_repos_default_branch(org)
25+
# print(org)
26+
for repo in org_repos:
27+
if repo[2] == old_branch:
28+
repos.append(repo)
29+
# print(repo)
30+
return repos
31+
32+
33+
def rename_branch(org, repo, old_name, new_name, dry_run=True):
34+
log = []
35+
gh_repo = gh.get_organization(org).get_repo(repo)
36+
log.append(gh_repo.full_name)
37+
38+
# Git reference of the branch that you wish to delete
39+
source = gh_repo.get_git_ref("heads/" + old_name)
40+
41+
# Create new branch from old branch
42+
log.append("create branch " + new_name)
43+
if not dry_run:
44+
gh_repo.create_git_ref("refs/heads/" + new_name, sha=source.object.sha)
45+
46+
# Delete old branch reference
47+
log.append("delete branch " + old_name)
48+
if not dry_run:
49+
source.delete()
50+
return log
51+
52+
53+
def csv_out(out_list: list):
54+
pass
55+
56+
57+
def confirm():
58+
input_confirm = input("Are you sure? yes/no:")
59+
if input_confirm == "yes":
60+
return 0
61+
return 1
62+
63+
64+
def which_orgs(input_selection, orgs):
65+
if input_selection == "a":
66+
# print("Running against all orgs")
67+
return orgs
68+
if (int(input_selection) - 1) > 0:
69+
# print("Running against " + orgs[int(input_selection) - 1])
70+
return [orgs[int(input_selection) - 1]]
71+
72+
73+
def main():
74+
print("Welcome to the GitHub Org Branch Name Changer!")
75+
input_dryrun = input("Is this a dry run? yes/no: ")
76+
dry_run = True
77+
if input_dryrun == "no":
78+
if confirm() == 0:
79+
dry_run = False
80+
print("\n\n*** ARMED! NOT A DRY RUN! ***\n\n")
81+
input_old_branch = input("Old default branch name: ")
82+
input_new_branch = input("New default branch name: ")
83+
orgs = get_orgs()
84+
85+
for count, org in enumerate(orgs):
86+
print(count + 1, org)
87+
88+
print("a all")
89+
90+
input_org_selection = input("\nOrg number: ")
91+
run_orgs = which_orgs(input_org_selection, orgs)
92+
repos = filtered_repos(run_orgs, input_old_branch)
93+
input("Ready. Continue?")
94+
if confirm() == 1:
95+
print("Abort!")
96+
return 0
97+
log_out = []
98+
for repo in repos:
99+
# rename_branch(org, repo, old_name, new_name, dry_run=True):
100+
log_out.append(
101+
rename_branch(repo[0], repo[1], input_old_branch, input_new_branch, dry_run)
102+
)
103+
for log in log_out:
104+
print(log)
105+
106+
107+
main()

githubuseradd.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# An OAuth access token is needed, see: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
2+
# Rate limit is 500 per day or 50 if you do not meet certain requirements.
3+
# For more informations see: https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs#set-organization-membership-for-a-user
4+
import requests
5+
import time
6+
import sys
7+
import getopt
8+
9+
examplecommandline = "Expecting 4 arguments: github_batchadd.py -o <your_organistionname> -u <github_username> -t <github_personal_token> -f <list_of_emails_input_file>"
10+
11+
if len(sys.argv) != 9:
12+
print(examplecommandline)
13+
sys.exit(2)
14+
15+
org = ""
16+
username = ""
17+
token = ""
18+
inputfile = ""
19+
20+
try:
21+
opts, args = getopt.getopt(
22+
sys.argv[1:],
23+
"ho:u:t:f:",
24+
["organisation=", "username=", "token=", "listofemailsfile="],
25+
)
26+
except getopt.GetoptError:
27+
print(examplecommandline)
28+
sys.exit(2)
29+
for opt, arg in opts:
30+
if opt == "-h":
31+
print(examplecommandline)
32+
sys.exit(0)
33+
elif opt in ("-o", "--iorganisation"):
34+
org = arg
35+
elif opt in ("-u", "--iusername"):
36+
username = arg
37+
elif opt in ("-t", "--itoken"):
38+
token = arg
39+
elif opt in ("-f", "--ifile"):
40+
inputfile = arg
41+
h = {"Content-type": "application/json", "Accept": "application/vnd.github.v3+json"}
42+
43+
try:
44+
with open(inputfile) as f:
45+
content = f.readlines()
46+
except:
47+
print("File could not be opened.")
48+
sys.exit(3)
49+
50+
content = [line.strip() for line in content]
51+
invitecount = 0
52+
for email in content:
53+
if email != "":
54+
r = requests.post(
55+
"https://github.com/api/orgs/" + org + "/invitations",
56+
headers=h,
57+
json={"invitee_id": email},
58+
auth=(username, token),
59+
)
60+
time.sleep(1)
61+
print(r.status_code, r.reason)
62+
print(r.text)
63+
if r.status_code != 201:
64+
print(
65+
"Error occurred. "
66+
+ str(invitecount)
67+
+ " have been invited. See error information above."
68+
)
69+
sys.exit(4)
70+
invitecount += 1
71+
print("Finished. " + str(invitecount) + " has been invited.")

hello.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python3
2+
3+
# print("Hello, world!")
4+
5+
6+
def get_festival_name(day_of_year):
7+
start_end_festival = [
8+
[152, 181, "pride"],
9+
[359, 359, "christmas"],
10+
[256, 256, "day_of_the_programmer"],
11+
[166, 166, "national-beer-day"],
12+
[103, 104, "vaisakhi"],
13+
# ad infinitum
14+
]
15+
16+
for festival in start_end_festival:
17+
if festival[0] <= day_of_year <= festival[1]:
18+
return festival[2]
19+
return "main"
20+
21+
22+
from datetime import datetime
23+
24+
25+
day_of_year_now = datetime.now().timetuple().tm_yday
26+
27+
logo_filename = " logo-" + get_festival_name(103) + ".svg"
28+
print(logo_filename)
29+
#
30+
# for day in range(1, 366):
31+
# logo_filename = (
32+
# str(day) + " logo-" + get_festival_name(day) + ".svg"
33+
# )
34+
# print(logo_filename)

meur.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/python3
2+
3+
# git branch --issue [issue key]
4+
# Standardised git branch creator based on ticket/issue key and title.
5+
#
6+
# Branches are created using the standard format of
7+
# [type]-[issue key]-[issue_title]
8+
#
9+
# Flow:
10+
# checkout default branch
11+
# generate branch name
12+
# create that branch
13+
# checkout that branch
14+
#
15+
# Limitations:
16+
# Compatible git platforms:
17+
# GitHub
18+
# Compatible issue trackers:
19+
# GitHub Issues
20+
# issue
21+
# ticket
22+
# Usage:
23+
# meur setup/help/version/[issue key] <command> [arg]
24+
#
25+
# Defaults are available if working from within a git inited directory.
26+
#
27+
# setup [username] setup meur for given GitHub [username].
28+
# Env vars saved to .gitconfig
29+
# -i --issuetracker issue tracker
30+
# github GitHub Issues
31+
# -k --key access key
32+
# default: config vars
33+
# [username].JIRA_API_TOKEN Jira Cloud API
34+
# Token
35+
# [username].GH_PAT GitHub Personal Access
36+
# Token
37+
# -j --jurl if using Jira, atlassian.net cloud instance URL
38+
# cname - https://[jurl].atlassian.net
39+
# default: env var
40+
# JIRA_URL
41+
#
42+
# help display this help
43+
# --h --help alias of help
44+
#
45+
# version show installed meur version
46+
# -v --version alias of version
47+
#
48+
# [issue key]
49+
# -a --alter Alters existing local and remote branch based
50+
# on current issue title. Subsequent flags
51+
# ignored.
52+
# default: create new branch from issue key
53+
# -u --username repo login name - http://github.com/[username]
54+
# default: current origin username
55+
# -r --repo repo name
56+
# default: current origin repo name
57+
# -t --type branch type
58+
# default: feature
59+
# -b --branch branch from current branch
60+
# default: cut from default branch
61+
62+

pit.py

Whitespace-only changes.

0 commit comments

Comments
 (0)