Skip to content

Commit 7e98fc9

Browse files
authored
new program files
1 parent 9690e76 commit 7e98fc9

23 files changed

+615
-0
lines changed

Arith_operation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#This program will peroferm arithmatic operation on input values provide by user
2+
3+
print('Please enter first number: ')
4+
num1=int(input())
5+
6+
print('Please enter second number: ')
7+
num2=int(input())
8+
#add=num1+num2
9+
#sub=num1-num2
10+
#mult=num1*num2
11+
#div=num1/num2
12+
#power=num1**num2
13+
#floor_div=num1//num2
14+
#modules=num1%num2
15+
print('Addition:', num1+num2)
16+
print('Substraction: ', num1-num2)
17+
print('Multiplication: ',num1*num2)
18+
print('Division: ',num1/num2)
19+
print('Power of number',num1**num2)
20+
print('floor division',num1//num2)
21+
print('Modules',num1%num2)
22+
23+

Character_classes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import re
2+
3+
lyrics='12 drummers are drumming 11 dhdhdh jhljhas 10 kjkasdj kjasdkj 9 kjksajd uyweruy 8 yuyquhk kalsjdlashd'
4+
5+
xmasregex=re.compile(r'\d+\s\w+')
6+
result=xmasregex.findall(lyrics)
7+
print(result)
8+

CountChar.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pprint
2+
3+
message = "This is just demo string..put your string here"
4+
5+
count = {}
6+
7+
for char in message.upper():
8+
count.setdefault(char, 0)
9+
count[char] = count[char]+1
10+
pprint.pprint(count)
11+
pformatetext = pprint.pformat(count)
12+
print(pformatetext)

Directory_walk.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Dec 11 10:22:31 2019
4+
5+
@author: anis.sayyad
6+
"""
7+
#program to walk through the Directory tree
8+
import os
9+
10+
for folder, subfolder, files in os.walk('C:\\Users\\anis.sayyad'):
11+
print('Folder in C directory:', folder)
12+
print('sub folders in',folder,'are:',subfolder)
13+
print('Files in',folder,'are:',files)
14+
print('\n')
15+
16+
for sub in subfolder:
17+
if 'anis.sayyad' in subfolder:
18+
print('Folder available')
19+
else:print('Not Available')
20+
21+
for file in subfolder:
22+
if 'Directory_walk.py' in subfolder:
23+
print('File is present...!')
24+
else:print('Not present..!')

GuessTheNumber.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#This program is to guess the random number
2+
3+
import random
4+
5+
print('Hello, What is your name:')
6+
name=input()
7+
8+
print('Well '+name+' I am thinking to guess a number between 1 to 20')
9+
10+
secretnumber=random.randint(1,20)
11+
12+
for i in range(1,7):
13+
print('Enter your guess:')
14+
guess = int(input())
15+
if guess < secretnumber:
16+
print('Your guess is too low')
17+
elif guess > secretnumber:
18+
print('Your guess is too high')
19+
else:
20+
break
21+
if guess == secretnumber:
22+
print('Good Job '+name+' You have guessed my number in ',i , ' attempts')
23+
else:
24+
print('Nope! The number i was thinking of '+str(secretnumber))

Hello.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#This program say's hello and ask for you name and age
2+
print('Hello worold!')
3+
print('What is your name?')
4+
myname=input()
5+
print('The lenght of your name is=')
6+
print(len(myname))
7+
print('what is your age=')
8+
myage=input()
9+
print('You must be '+str(int(myage)+1)+' next year')

PhoneNemailScraper.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#This program is to get the Phone number and email address from the large text file using pyperclip and regex modules.
2+
import re
3+
#import pyperclip
4+
5+
#Create a Regex for phone number
6+
phoneRegex=re.compile(r'''
7+
#415-555-6758, 555-7878, (415) 765-1234, 665-6456 extn 12345, ext.12347, x12345
8+
(
9+
((\d\d\d)|(\(\d\d\d\)))? #area code(Optional)
10+
(\s|-) #first seprator
11+
\d\d\d #first three digit.
12+
- #seprator
13+
\d\d\d\d #last 4 digits
14+
(((ext(\.)?\s)|x) #extension word part
15+
(\d{2,5}))? #extension number part
16+
)
17+
''', re.VERBOSE)
18+
#create regex for email address.
19+
emailRegex= re.compile('''
20+
#some.+_thing@(\d{2,5}))?.com\
21+
[a-zA-Z0-9_.+]+ #name part
22+
@ # @symbol
23+
[a-zA-Z0-9_.+]+ #domain name part
24+
''', re.VERBOSE)
25+
#get the text off the clipboard
26+
#text=pyperclip.paste()
27+
text='''
28+
anis has 343-364-4363 anis.saya@gml.com
29+
anis has 704-048-9515 anis.saya@gml.com
30+
anis has 343-364-4363 anis.saya@gml.com
31+
anis has 343-364-4363 anis.saya@gml.com
32+
anis has 343-364-4363 anis.saya@gml.com
33+
'''
34+
#extract phone and mail from this text
35+
extractphone = phoneRegex.findall(text)
36+
extractmail = emailRegex.findall(text)
37+
38+
allphonenumber =[]
39+
for i in allphonenumber:
40+
allphonenumber.append(i[0])
41+
result = '\n'.join(allphonenumber) + '\n' + '\n'.join(extractmail)
42+
print(result)
43+
#print(extractmail)
44+
45+
#pyperclip.copy(result)
46+
47+
48+

Pipe.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import re
2+
regulerexprstring = re.compile("Bat(man|mobile|bat|pat)")
3+
mo=regulerexprstring.search("This string contains the Batmobile")
4+
if mo==(None):
5+
print("This string not contains any regular expression")
6+
else:
7+
print(mo.group())
8+

Repetition.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
3+
regex = re.compile(r'(\?\*\+)?') # ? means 0 or 1
4+
5+
regex = re.compile(r'(\?\*\+)*') # * means 0 or more
6+
7+
regex = re.compile(r'(\?\*\+)+') # + means 1 or More
8+
9+
mo=regex.search("This is just demo of matching ?*+?*+")
10+
11+
12+
print(mo.group())

assertdemo.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
market_2nd={'ns':'green','ew':'red'}
2+
def switchlights(intersection):
3+
for key in intersection.keys():
4+
if intersection[key]=='green':
5+
intersection[key]='yellow'
6+
elif intersection[key]=='yellow':
7+
intersection[key]='red'
8+
elif intersection[key]=='red':
9+
intersection[key]='green'
10+
assert 'red' in intersection.values(), 'Neither light is red' + str(intersection)
11+
12+
switchlights(market_2nd)

bitbucket_to_git_migration.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import os
2+
import requests
3+
import json
4+
import subprocess
5+
import shutil
6+
7+
# Access stored environmental variables for username and password
8+
Bitbucket_User = os.environ['BITBUCKET_USER']
9+
Bitbucket_Pass = os.environ['BITBUCKET_PASS']
10+
Git_User = os.environ['GIT_USER']
11+
Git_Token = os.environ['GIT_TOKEN']
12+
13+
team_id = 0
14+
empty_git_repo_list = []
15+
github_existing_team_list = []
16+
bitbucket_git_repo_list = []
17+
repo_project_mapping = {}
18+
bitbucket_project_list = []
19+
bitbucket_nongit_repo_list = []
20+
git_repo_team_mapping = {}
21+
22+
# Create a list of existing bitbucket repo names
23+
24+
bitbucket_url = 'https://api.bitbucket.org/2.0/repositories/edgenuity?pagelen=100'
25+
headers = {'Content-Type':'application/json'}
26+
response = requests.get(url=bitbucket_url,headers=headers,auth=(Bitbucket_User,Bitbucket_Pass))
27+
response_json = json.loads(response.text)
28+
for repo in response_json['values']:
29+
if 'project' in repo:
30+
repo_project_mapping[repo['slug'].encode("utf-8")] = repo['project']['name'].encode("utf-8")
31+
if repo['project']['name'] not in bitbucket_project_list:
32+
bitbucket_project_list.append(repo['project']['name'])
33+
if repo['scm']!= "git":
34+
bitbucket_nongit_repo_list.append(repo['slug'].encode("utf-8"))
35+
else:
36+
bitbucket_git_repo_list.append(repo['slug'].encode("utf-8"))
37+
38+
while True:
39+
if "next" in response_json:
40+
print "More repos exist"
41+
bitbucket_url = response_json["next"]
42+
headers = {'Content-Type':'application/json'}
43+
response = requests.get(url=bitbucket_url,headers=headers,auth=(Bitbucket_User,Bitbucket_Pass))
44+
response_json = json.loads(response.text)
45+
for repo in response_json['values']:
46+
if 'project' in repo:
47+
repo_project_mapping[repo['slug'].encode("utf-8")] = repo['project']['name'].encode("utf-8")
48+
if repo['project']['name'] not in bitbucket_project_list:
49+
bitbucket_project_list.append(repo['project']['name'])
50+
if repo['scm']!= "git":
51+
bitbucket_nongit_repo_list.append(repo['slug'].encode("utf-8"))
52+
else:
53+
bitbucket_git_repo_list.append(repo['slug'].encode("utf-8"))
54+
else:
55+
print "All repos covered"
56+
break
57+
58+
print bitbucket_project_list
59+
#print repo_project_mapping
60+
#print bitbucket_git_repo_list
61+
print bitbucket_nongit_repo_list
62+
print len(bitbucket_project_list)
63+
print len(bitbucket_nongit_repo_list)
64+
print len(bitbucket_git_repo_list)
65+
66+
git_repo_url = 'https://api.github.com/orgs/edgenuity/repos'
67+
git_team_url = 'https://api.github.com/orgs/edgenuity/teams'
68+
git_add_repo_to_team_url = 'https://api.github.com/teams'
69+
git_headers = {'Content-Type':'application/json','Authorization':'token '+ Git_Token}
70+
git_team_repo_mapping_headers = {'Content-Type':'application/json','Authorization':'token '+ Git_Token,'Accept':'application/vnd.github.hellcat-preview+json'}
71+
72+
for repo_name in bitbucket_git_repo_list:
73+
create = True
74+
if repo_name in repo_project_mapping:
75+
print repo_name
76+
team_name = repo_project_mapping[repo_name]
77+
print team_name
78+
# Check if team exists on github, if not, create it
79+
response = requests.get(url=git_team_url+'?per_page=100',headers=git_headers)
80+
response_json = json.loads(response.text)
81+
print len(response_json)
82+
for team in response_json:
83+
if team['name'] not in github_existing_team_list:
84+
github_existing_team_list.append(team['name'].encode("utf-8"))
85+
if team_name == team['name']:
86+
team_id = team['id']
87+
print team_id
88+
create = False
89+
break
90+
#print github_existing_team_list
91+
#print len(github_existing_team_list)
92+
if create == True:
93+
print "Team not present, creating it"
94+
try:
95+
team_create_data = {'name': team_name,'description': 'This is '+team_name+' team','privacy': 'secret'}
96+
# Create team on github having same name as that of bitbucket project
97+
response = requests.post(url=git_team_url,headers=git_headers,data=json.dumps(team_create_data))
98+
print response.text
99+
response_json = json.loads(response.text)
100+
if 'errors' in response_json:
101+
if response_json['errors'][0]['message'] == "Name has already been taken":
102+
raise ValueError("Duplicate team name")
103+
else:
104+
# Store team id for future purposes
105+
global team_id
106+
team_id = response_json['id']
107+
print team_id
108+
109+
except ValueError as e:
110+
print str(e)
111+
continue
112+
try:
113+
repo_create_data = {'name': repo_name,'description': 'This is '+repo_name+' repository','homepage': 'https://github.com/edgenuity/'+repo_name,'private': True,'has_issues': True,'has_projects': True,'has_wiki': True}
114+
# Create an empty Git repo having same name as the bitbucket repo
115+
response = requests.post(url=git_repo_url,headers=git_headers,data=json.dumps(repo_create_data))
116+
print response.text
117+
# If repo is already present on Github, there is every chance that code will also be present so skpping next steps to speed up execution
118+
if int(response.status_code)!= 422:
119+
# Clone existing bitbucket repo
120+
clone_cmd = "git clone --mirror https://"+Bitbucket_User+":"+Bitbucket_Pass+"@bitbucket.org/edgenuity/"+repo_name+".git"
121+
subprocess.call(clone_cmd,shell=True)
122+
working_dir = os.getcwd()
123+
os.chdir(repo_name+".git")
124+
# Rename existing Git remote connection to bitbucket
125+
rename_origin_cmd = "git remote rename origin bitbucket"
126+
subprocess.call(rename_origin_cmd,shell=True)
127+
# Add remote origin as Git's newly created repo
128+
add_git_origin_cmd = "git remote add origin https://"+Git_User+":"+Git_Token+"@github.com/edgenuity/"+repo_name+".git"
129+
subprocess.call(add_git_origin_cmd,shell=True)
130+
# Set remote git url
131+
set_git_url_cmd = "git remote set-url --push origin https://"+Git_User+":"+Git_Token+"@github.com/edgenuity/"+repo_name+".git"
132+
subprocess.call(set_git_url_cmd,shell=True)
133+
# Push all branches in the repo
134+
git_push_branches_cmd = "git push --mirror"
135+
subprocess.call(git_push_branches_cmd,shell=True)
136+
# Remove remote bitbucket origin
137+
remove_bitbucket_origin_cmd = "git remote rm bitbucket"
138+
subprocess.call(remove_bitbucket_origin_cmd,shell=True)
139+
os.chdir(working_dir)
140+
# Remove cloned bitbucket repo after pushing code to free up space
141+
shutil.rmtree(repo_name+".git")
142+
# Add github repository to team
143+
response = requests.put(url=git_add_repo_to_team_url+"/"+str(team_id)+"/repos/edgenuity/"+repo_name,headers=git_team_repo_mapping_headers)
144+
print response.text
145+
if int(response.status_code) == 204:
146+
print "Repo successfully added to team"
147+
else:
148+
raise ("Repo could not be added to the team")
149+
except Exception as e:
150+
print str(e)
151+
152+
print "Teams on Github are: " +str(github_existing_team_list)
153+
print "Number of teams on Github are: " +str(len(github_existing_team_list))
154+
155+
# Get a list of almost empty Git repos which are almost empty due to either code not getting pushed into it or source repo did not have any code
156+
# Iterating for 7 times as repo number is between 600 to 700
157+
for i in range (1,8):
158+
print i
159+
response = requests.get(url=git_repo_url+'?page='+str(i)+'&per_page=100',headers=git_headers)
160+
print response.text
161+
response_json = json.loads(response.text)
162+
print len(response_json)
163+
for repo in response_json:
164+
if int(repo['size']) == 0:
165+
empty_git_repo_list.append(repo['name'].encode("utf-8"))
166+
167+
print "Almost empty Github repo names are:" +str(empty_git_repo_list)
168+
print "Number of almost empty Github repo names are:" +str(len(empty_git_repo_list))
169+

0 commit comments

Comments
 (0)