Skip to content

Commit 34957db

Browse files
authored
Merge branch 'master' into all-contributors/add-rahulraikwar00
2 parents e4ce748 + b803e03 commit 34957db

File tree

12 files changed

+298
-0
lines changed

12 files changed

+298
-0
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@
504504
"code",
505505
"doc"
506506
]
507+
},
508+
{
509+
"login": "iamakkkhil",
510+
"name": "Akhil Bhalerao",
511+
"avatar_url": "https://avatars.githubusercontent.com/u/55273506?v=4",
512+
"profile": "https://www.linkedin.com/in/akhil-bhalerao-63b47a193/",
513+
"contributions": [
514+
"code",
515+
"doc"
516+
]
507517
}
508518
],
509519
"contributorsPerLine": 7,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Distance Calculating App
2+
Calculating distance between two locations is a basic requirement if you are working with raw location data. This app calculates distance between two geo-locations. You can get distance in kilometers between two locations just by entering names of the locations.
3+
4+
## Quick Start:
5+
6+
- Change Directory
7+
8+
``` cd .\Rotten-Scripts\Python\Distance_Calculator_App\ ```
9+
10+
- Install requirememnts
11+
12+
`pip install -r requirements.txt`
13+
14+
- Run python file
15+
16+
`python main.py --firstlocation <enter first location here> --secondlocation <enter second location here>`
17+
18+
## Screenshot
19+
20+
![Screenshot](https://i.imgur.com/r7ImdqE.jpg)
21+
22+
## Author
23+
[Aayush Garg](https://github.com/Aayush-hub)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import argparse
2+
from geopy.geocoders import Nominatim
3+
from geopy import distance
4+
5+
def location():
6+
""" A program to calculate distance between two geo-locations
7+
Parameters:
8+
firstlocation (str): The starting location of user
9+
secondlocation (str): The final location of user
10+
11+
"""
12+
geolocator = Nominatim(user_agent="geoapiExercises")
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument('--firstlocation', type=str, required=True)
15+
parser.add_argument('--secondlocation', type=str, required=True)
16+
args = parser.parse_args()
17+
18+
# calculating longitude and latitude of entered locations """
19+
try:
20+
first_location = geolocator.geocode(args.firstlocation)
21+
second_location = geolocator.geocode(args.secondlocation)
22+
Loc1_lat,Loc1_lon = (first_location.latitude),(first_location.longitude)
23+
Loc2_lat,Loc2_lon = (second_location.latitude),(second_location.longitude)
24+
25+
location1=(Loc1_lat,Loc1_lon)
26+
location2=(Loc2_lat,Loc2_lon)
27+
28+
# calculating and printing distance between locations in Kilometers and Miles."""
29+
30+
res = ((distance.distance(location1, location2).km))
31+
distance_miles = float(res)*0.621371
32+
print (f"The total distance is: {res} Km , {distance_miles} Miles")
33+
except:
34+
print("Invalid Location")
35+
36+
if __name__ == "__main__":
37+
location()
38+
58 Bytes
Binary file not shown.

Python/PR_Workflow/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# GitHub CLI
2+
3+
`pwr` is Pull Requests Workflow on the command line. It brings OPEN, CLOSED,MERGED and other PR concepts to the terminal next to where you are already working with `git` and your code.
4+
`prw` is available for repositories hosted on GitHub.com.
5+
6+
## Setup instructions
7+
8+
<b>it requires a Github Personal Access Token (PAT) to verify the user</b>
9+
10+
| Install: | Run: |
11+
| ----------------- | ---------------------------- |
12+
| `bash install.sh` | `Python prw.py --help` |
13+
| | `python prw.py auth <token>` |
14+
15+
## available commands
16+
17+
- `auth <token> `
18+
- `repo <username/repo_name> [options] [mode] `
19+
20+
## Output
21+
22+
![Screenshot](https://i.imgur.com/jV8qgOG.png)
23+
24+
## Author
25+
26+
<b>[Rahul Raikwar](https://github.com/rahulraikwar00)</i>
27+
28+
## Disclaimers, if any
29+
30+
<i>This script requires a Github Personal Access Token (PAT) to verify the user</i>
31+
<i>It does not have a specialized `upgrade` command yet, but the `install` command should work for upgrading to a newer version of GitHub prw.</i>

Python/PR_Workflow/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c9a6sample-tokena097a9c83f9

Python/PR_Workflow/prw.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import click
2+
import requests
3+
from src.extracktor import json_extract
4+
from src.graphqlapi import Queries
5+
from src.prapi import run_query
6+
7+
8+
@click.group()
9+
def main():
10+
"""
11+
Work with GitHub pull requests.\n
12+
prw <command> <argument> [options] [flags]
13+
"""
14+
15+
16+
@main.command()
17+
@click.option('-t', '--tag', type=str, help="Search pull request by tag[case sensitive]")
18+
@click.option('-s', '--state', type=click.Choice(['open', 'closed', 'merged']), required=True, help="Show recent merged pull request")
19+
@click.option('-v', '--verbose', is_flag=True, help="enable verbose mode")
20+
@click.option('-p', '--pages', type=int, default=1, help="Show result up to pages")
21+
@click.argument('repos', type=str, required=True)
22+
def repo(repos, state, pages, tag=None, verbose=False, ):
23+
"""This function checks the valid configuration
24+
and calls the API on the given repository with arguments and options
25+
and also prints the output
26+
"""
27+
if pages > 3:
28+
click.secho("You can not see more than 3 pages.!", fg='red', bold=True)
29+
return
30+
pages = pages*30
31+
state = state.upper()
32+
flag = True
33+
stcolor = {"OPEN": "green", "CLOSED": "red", "MERGED": "yellow"}
34+
try:
35+
#read configuration from config.ini file
36+
with open('config.ini', 'r') as cf:
37+
token = cf.read()
38+
if len(token) != 40:
39+
raise Exception
40+
except:
41+
if flag:
42+
click.secho('Please Verify Your github Token first.!',
43+
bold=True, fg='red')
44+
click.echo('Usage : auth <token> ')
45+
else:
46+
r = repos.split("/")
47+
if len(r) < 2:
48+
click.echo(click.secho("SyntaxError:", fg='red', bold=True) +
49+
click.echo('invalid syntax for repo : username/repo_name'))
50+
return
51+
else:
52+
result = run_query(
53+
Queries(f"{r[0]}", f"{r[1]}", state, tag, pages).pulls(), token)
54+
if verbose:
55+
print("This feature has not been added yet..comming soon")
56+
else:
57+
58+
click.secho(state, fg=stcolor[state], bold=True)
59+
for i in result['data']['repository']['pullRequests']['nodes']:
60+
number = json_extract(i, 'number')
61+
title = json_extract(i, 'title')
62+
totalCount = json_extract(i, 'totalCount')
63+
lname = json_extract(i, 'name')
64+
click.secho(
65+
f"#{number[0]} ", fg=stcolor[state], bold=True, nl=False)
66+
print(
67+
f"Title :{title[0]} ----------> Comments :{totalCount[0]} ---------> labels{lname}")
68+
69+
70+
@main.command()
71+
@click.argument('token')
72+
def auth(token):
73+
""" Verify Api with GitHub token\n
74+
example: prw.py auth <token>
75+
"""
76+
if len(token) == 40:
77+
with open('config.ini', 'w') as cf:
78+
cf.write(token)
79+
click.secho('Verification Successfull 👍', fg='green', bold=True)
80+
else:
81+
click.secho('Incorrect token please retry..!', fg='red', bold=True)
82+
83+
84+
def start():
85+
"""
86+
prw <command> <argument> [options] [flags]
87+
"""
88+
89+
main(obj={})
90+
91+
92+
if __name__ == '__main__':
93+
start()

Python/PR_Workflow/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.25.1
2+
click==7.1.2

Python/PR_Workflow/src/extracktor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
def json_extract(obj, key):
3+
"""Recursively fetch values from nested JSON."""
4+
arr = []
5+
6+
def extract(obj, arr, key):
7+
"""Recursively search for values of key in JSON tree."""
8+
if isinstance(obj, dict):
9+
for k, v in obj.items():
10+
if isinstance(v, (dict, list)):
11+
extract(v, arr, key)
12+
elif k == key:
13+
arr.append(v)
14+
elif isinstance(obj, list):
15+
for item in obj:
16+
extract(item, arr, key)
17+
return arr
18+
19+
values = extract(obj, arr, key)
20+
return values

Python/PR_Workflow/src/graphqlapi.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
class Queries:
3+
"""The Queries class defines an object that represents a pull request query"""
4+
5+
def __init__(self, owner, name, state, tag=None, countr=30):
6+
""" initialize query object with state, name, owner, tag and counter."""
7+
self.name = name
8+
self.owner = owner
9+
self.tag = tag
10+
self.state = state
11+
self.countr = countr
12+
13+
def pulls(self):
14+
if self.tag != None:
15+
query = """
16+
{ repository(name: "%s", owner: "%s") {
17+
pullRequests(states: %s, last: %i, orderBy: {field: CREATED_AT, direction: ASC},labels:"%s") {
18+
totalCount
19+
nodes {
20+
title
21+
number
22+
comments {
23+
totalCount
24+
}
25+
closedAt
26+
createdAt
27+
labels(last: 10) {
28+
nodes {
29+
name
30+
}
31+
totalCount
32+
}
33+
}
34+
}
35+
}
36+
}
37+
""" % (self.name, self.owner, self.state, self.countr, self.tag)
38+
return query
39+
else:
40+
query = """
41+
{
42+
repository(name: "%s", owner: "%s") {
43+
pullRequests(states: %s, last: %s, orderBy: {field: CREATED_AT, direction: ASC}) {
44+
totalCount
45+
nodes {
46+
title
47+
number
48+
comments {
49+
totalCount
50+
}
51+
closedAt
52+
createdAt
53+
labels(last: 10) {
54+
nodes {
55+
name
56+
}
57+
totalCount
58+
}
59+
}
60+
}
61+
}
62+
}
63+
""" % (self.name, self.owner, self.state, self.countr)
64+
return query

0 commit comments

Comments
 (0)