Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 182d564

Browse files
Merge pull request #1 from ankitdobhal/master
updating forked repo
2 parents a56e9b2 + e08f365 commit 182d564

File tree

206 files changed

+7080
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+7080
-41
lines changed

Basic-Scripts/Compress_the_string.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from itertools import groupby
2+
uncompressed = str(input("Enter string to compress: ")) # user input for string
3+
print(*[(len(list(value)), str(key)) for key, value in groupby(uncompressed)]) # logic to print occurence of values in string

Basic-Scripts/Dat_to_CSV/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Dat to CSV
2+
3+
This simple script can be used to convert files in ".dat" format to ".csv" format.
4+
5+
6+
## How to use this script?
7+
8+
1.Install the required libraries by:
9+
10+
pip install -r requirements.txt
11+
12+
2. Open your command prompt in the directory of the script and type the following:
13+
14+
python dat_to_csv.py -l <your_data-file>
15+
16+
Example:
17+
18+
python dat_to_csv.py -l awesome.dat
19+
20+
21+
22+
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pandas as pd
2+
import argparse
3+
4+
# Code to add the command line interface
5+
parser = argparse.ArgumentParser()
6+
parser.add_argument("-l", "--datafile", required=True, help="data file ")
7+
args = vars(parser.parse_args())
8+
9+
#Catching the user defined data file
10+
data_file = args['datafile']
11+
12+
#Logic to make sure it is a data file.A data file ends with .dat extension
13+
14+
if data_file.endswith(".dat"):
15+
16+
#Storing the name of the file
17+
file_name = data_file.split(".")[0]
18+
19+
#Collecting data of the file in a pandas object
20+
data_of_the_file = pd.read_csv(data_file, sep="\s+")
21+
22+
#Converting the pandas object into a csv
23+
data_of_the_file.to_csv(file_name+".csv", index=False)
24+
print("Your csv file has been created successfully!!!")
25+
else:
26+
print("Invalid data file")
27+
28+
#Sample Input-Output:
29+
30+
#Input(At the command line): python dat_to_csv -l awesome.dat
31+
#Output: awesome.csv
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
numpy==1.19.1
2+
pandas==1.1.1
3+
python-dateutil==2.8.1
4+
pytz==2020.1
5+
six==1.15.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Geocoding and Reverse Geocoding
2+
3+
#### This script takes an address and return its latitude and longitude.This process is called geocoding
4+
#### It can also perform the opposite operation that is take latitude, longitude and provide address.
5+
6+
#### I have used the LocationIQ website's geocoding api inorder to solve this problem.
7+
8+
#### In order to run this script you need to have a private token which is just a key for the api..
9+
10+
#### To obtain your own private token create a *free account* at https://locationiq.com/ and replace my private token with yours.
11+
12+
#### Remember, *don't share* your private token with anyone if you use your personal email for account creation.
13+
14+
#### Install the dependencies by using:
15+
16+
pip install -r requirements.txt
17+
18+
#### An Example of the script in action:
19+
20+
<img src="Sample.PNG" alt="Sample">
21+
22+
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import requests
2+
import sys
3+
4+
# If you want your own private_token please refer the README file for this script.
5+
private_token = "<Your Private Token>"
6+
7+
while True:
8+
choice = input(
9+
"Type G for geocoding , type R for reverse geocoding and type Q to quit the script:")
10+
print()
11+
12+
# If the user choose to perform Geocoding
13+
if choice.upper() == 'G':
14+
# Base Url for geocoding
15+
url = "https://us1.locationiq.com/v1/search.php"
16+
17+
address = input("Input the address: ")
18+
19+
# Parameters for the geocoding url
20+
data = {
21+
'key': private_token,
22+
'q': address,
23+
'format': 'json'
24+
}
25+
26+
response = requests.get(url, params=data)
27+
28+
# To run only if we get success response
29+
if response.status_code == 200:
30+
latitude = response.json()[0]['lat']
31+
longitude = response.json()[0]['lon']
32+
33+
print(f"The latitude of the given address is: {latitude}")
34+
print(f"The longitude of the given address is: {longitude}")
35+
print()
36+
else:
37+
sys.exit("Cant find what you where looking for")
38+
39+
# If the user choose to perform Reverse Geocoding
40+
elif choice.upper() == 'R':
41+
# Base Url for reverse geocoding
42+
url = "https://us1.locationiq.com/v1/reverse.php"
43+
44+
latitude_reverse = input("Enter the latitude: ")
45+
longitude_reverse = input("Enter the longitude: ")
46+
47+
# Parameters for the reverse geocoding url
48+
data = {
49+
'key': private_token,
50+
'lat': latitude_reverse,
51+
'lon': longitude_reverse,
52+
'format': 'json'
53+
}
54+
55+
response = requests.get(url, params=data)
56+
57+
# To run only if we get success response
58+
if response.status_code == 200:
59+
address = response.json()['display_name']
60+
print(f"The address is: {address}")
61+
print()
62+
else:
63+
print("Cant find what you where looking for.")
64+
65+
# If the user choose to Quit the program
66+
elif choice.upper() == 'Q':
67+
sys.exit("Thanks for using the script")
68+
69+
# To make sure only valid input is provided
70+
else:
71+
print("Please make a valid choice")
72+
print()
73+
74+
#Sample Input - Output:
75+
76+
#If you choose Geocoding:
77+
78+
#Address(Input): Rashtrapati Bhavan
79+
#Latitude(Output): 28.614458
80+
#Longitude(Output): 77.199594
81+
82+
#If you choose Reverse-Geocoding:
83+
84+
#Latitude(Input): 28.614458
85+
#Longitude(Input): 77.199594
86+
#Address(Output): Rashtrapati Bhavan, Rajpath, Presidential Estate, Chanakya Puri Tehsil, New Delhi, Delhi, 110004, India
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
certifi==2020.6.20
2+
chardet==3.0.4
3+
idna==2.10
4+
requests==2.24.0
5+
urllib3==1.25.10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# function to convert infix to postfix using array as stack
2+
def infix_to_postfix(infix_expression):
3+
"""
4+
Function to change infix expression to postfix one
5+
Params:
6+
infix_expression: Infix Expression provided by user
7+
Returns:
8+
postfix_expression: Postfix Expression convertef from Infix one
9+
"""
10+
11+
# initially empty stack
12+
stack = []
13+
# initially empty postfix_expression
14+
postfix_expression = ""
15+
for char in infix_expression:
16+
# if an operand then put it directly in postfix expression
17+
if char not in operators:
18+
postfix_expression += char
19+
# else if operators should be put in stack
20+
elif char == "(":
21+
"""append function to push
22+
elements in the stack"""
23+
stack.append("(")
24+
elif char == ")":
25+
while stack and stack[-1] != "(":
26+
postfix_expression += stack.pop()
27+
""" pop function to pop
28+
elements from stack in LIFO order """
29+
stack.pop()
30+
else:
31+
"""if priority of char in infix_expression is less than or equal to
32+
char at stack[-1] pop out and put in postfix_expression"""
33+
while (
34+
stack and stack[-1] != "(" and priorities[char] <= priorities[stack[-1]]
35+
):
36+
postfix_expression += stack.pop()
37+
stack.append(char)
38+
while stack:
39+
postfix_expression += stack.pop()
40+
return postfix_expression
41+
42+
43+
# Set of operators
44+
operators = set(["+", "-", "*", "/", "(", ")", "^"])
45+
46+
# dictionary having priorities
47+
priorities = {"+": 1, "-": 1, "*": 2, "/": 2, "^": 3}
48+
49+
print("Input")
50+
infix_expression = input("Enter infix expression\n")
51+
print("Output")
52+
53+
# Displaying the Output
54+
print("Postfix expression: ", infix_to_postfix(infix_expression))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### Infix to Postfix
2+
3+
> • In Infix expression operator is in between every pair of operands.<br>
4+
> • In Postfix expression, the operator is followed for every pair of operands.
5+
6+
> Infix expression is converted to postfix conversion using Stack.
7+
> Postfix expression is evaluated using Stack in Left to Right order.
8+
9+
##### If the scanned character is operand, show it as output. Else, If precedence of scanned operator is greater than the precedence of the operator in the stack,push it.
10+
11+
> Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator.
12+
13+
• If the scanned input is '(', push it into stack<br>
14+
• If the scanned input is ')' ,pop the stack and the output it until '(' comes.<br>
15+
• Repeat above steps. Continue Pop and output from stack until it becomes empty.
16+
17+
##### It makes the code more efficient and even reduces the time complexity.
18+
### Constraints
19+
"""
20+
Input:
21+
Enter infix expression: A+C*(B^D-E)^(G+H*K)-K
22+
Output:
23+
Postfix expression: ACBD^E-GHK*+^*+K-
24+
25+
Time Complexity : O(n)
26+
Space Complexity: Θ(n)
27+
"""

Basic-Scripts/Menu_Driven.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""This code basically automates various system operations.
2+
It is a very interactive and user-friendly program
3+
The two modules used are os and pyttsx3."""
4+
5+
def system_operations():
6+
import pyttsx3
7+
import os
8+
pyttsx3.speak("Feel free to type in any statement!")
9+
while(True):
10+
11+
operation=input("Please type which operation you want to peform? :\n ")
12+
13+
print()
14+
operation= operation.lower()
15+
16+
if("chrome" in operation) or ("browser" in operation):
17+
pyttsx3.speak("Please wait opening chrome for you")
18+
os.system("chrome")
19+
20+
elif("notepad" in operation) or ("text editor" in operation) or ("text document" in operation):
21+
pyttsx3.speak("Please wait opening notepad for you")
22+
os.system("notepad")
23+
24+
elif("media player" in operation) or ("player" in operation) or ("windows media player" in operation):
25+
pyttsx3.speak("Please wait opening media player for you")
26+
os.system("wmplayer")
27+
28+
elif("visual studio code" in operation) or ("vs code" in operation) or ("vs" in operation):
29+
pyttsx3.speak("Please wait opening vs code for you")
30+
os.system("code")
31+
32+
elif("Git Hub" in operation) or ("github" in operation):
33+
pyttsx3.speak("Please wait opening github for you")
34+
os.system("GitHubDesktop")
35+
36+
elif("microsoft edge" in operation) or ("edge" in operation) or ("microsoft browser" in operation):
37+
pyttsx3.speak("Please wait opening microsoft edge for you")
38+
os.system("msedge")
39+
40+
elif("team viewer" in operation) or ("teamviewer" in operation):
41+
pyttsx3.speak("Please wait opening team viewer for you")
42+
os.system("TeamViewer")
43+
44+
elif("microsoft paint" in operation) or ("ms paint" in operation) or ("paint" in operation):
45+
pyttsx3.speak("Please wait opening microsoft edge for you")
46+
os.system("msedge")
47+
48+
elif("website" in operation) or ("link" in operation) or ("page" in operation) or ("chrome website" in operation) or ("chrome page" in operation):
49+
website=input("Enter the link for the website or page you want to open: \n")
50+
pyttsx3.speak("Please wait opening {} for you".format(website))
51+
os.system("chrome {}".format("website"))
52+
53+
elif("microsoft word" in operation) or ("ms word" in operation) or ("word" in operation):
54+
pyttsx3.speak("Please wait opening microsoft word for you")
55+
os.system("winword")
56+
57+
elif("exit" in operation) or ("return" in operation) or ("close" in operation) or ("end" in operation):
58+
pyttsx3.speak("Thank You! Hope to see you again")
59+
break
60+
61+
else:
62+
print("Error: Try some other operation available from the list!")
63+
pyttsx3.speak("Please enter some other operation")
64+
print()
65+
66+
def main():
67+
68+
import os
69+
import pyttsx3
70+
print()
71+
pyttsx3.speak("Welcome to the automation world")
72+
print(" This Is A Menu Drive Program ! ")
73+
print()
74+
print("Available Operations:")
75+
print("1) Open Chrome \n2) Open Notepad \n3) Open Media Player \n4) Open VS Code \n5) Open Git Hub \n6) Open any Website")
76+
print("7) Open Microsoft Edge \n8) Open Team Viewer(TeamViewer) \n9) Open MS Paint(mspaint) \n10) Open MS Word ")
77+
print()
78+
print("You can type a statement and interact!")
79+
print()
80+
81+
system_operations()
82+
83+
if __name__ == "__main__":
84+
main()

Basic-Scripts/Password/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1>Hard to guess easy to remember</h1>
2+
<p>Python script to generate a <b>password</b> which is almost <b>impossible to guess</b> by a attacker, by <b>using the easily remembered words</b> of a user day to day life.</p>
3+
4+
Here I use built-in python <b>module</b> name <b>random</b> use to make random choice.

0 commit comments

Comments
 (0)