Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/linrakesh/python
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Mar 31, 2020
2 parents 5addfcb + 9a5c00d commit dc208a4
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Loops/cube_of_digit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
x = input('Enter any number ')
sum = 0
for i in x:
y = int(i)
a = y**3
sum = sum+a

print(sum)
1 change: 1 addition & 0 deletions Loops/saneep_sis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("hello sandeep. Its was a nice meeting with you")
16 changes: 16 additions & 0 deletions Tools/SampleData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Rank,Name,Platform,Year,Genre,Publisher,NA_Sales,EU_Sales,JP_Sales,Other_Sales,Global_Sales
1,Wii Sports,Wii,2006,Sports,Nintendo,41.49,29.02,3.77,8.46,82.74
2,Super Mario Bros.,NES,1985,Platform,Nintendo,29.08,3.58,6.81,0.77,40.24
3,Mario Kart Wii,Wii,2008,Racing,Nintendo,15.85,12.88,3.79,3.31,35.82
4,Wii Sports Resort,Wii,2009,Sports,Nintendo,15.75,11.01,3.28,2.96,33
5,Pokemon Red/Pokemon Blue,GB,1996,Role-Playing,Nintendo,11.27,8.89,10.22,1,31.37
6,Tetris,GB,1989,Puzzle,Nintendo,23.2,2.26,4.22,0.58,30.26
7,New Super Mario Bros.,DS,2006,Platform,Nintendo,11.38,9.23,6.5,2.9,30.01
8,Wii Play,Wii,2006,Misc,Nintendo,14.03,9.2,2.93,2.85,29.02
9,New Super Mario Bros. Wii,Wii,2009,Platform,Nintendo,14.59,7.06,4.7,2.26,28.62
10,Duck Hunt,NES,1984,Shooter,Nintendo,26.93,0.63,0.28,0.47,28.31
11,Nintendogs,DS,2005,Simulation,Nintendo,9.07,11,1.93,2.75,24.76
12,Mario Kart DS,DS,2005,Racing,Nintendo,9.81,7.57,4.13,1.92,23.42
13,Pokemon Gold/Pokemon Silver,GB,1999,Role-Playing,Nintendo,9,6.18,7.2,0.71,23.1
14,Wii Fit,Wii,2007,Sports,Nintendo,8.94,8.03,3.6,2.15,22.72
15,Wii Fit Plus,Wii,2009,Sports,Nintendo,9.09,8.59,2.53,1.79,22
11 changes: 11 additions & 0 deletions Tools/css_beautifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from yattag import indent
with open("E:/python/Tools/style.css", "r") as file:
data = file.read()

result = indent(
data,
indentation=' ',
newline='\r\n',
indent_text=True
)
print(result)
21 changes: 21 additions & 0 deletions Tools/csv_to_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# python program to convert any csv file into html file
# made by : rakesh kumar

import csv
html = "<table>"
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
count = 1
for row in csv_data:
html += "<tr>"
if count == 1:
for y in row:
html += "<th>"+y+"</th>"
else:
for y in row:
html += "<td>"+y+"</td>"
html += "</tr>"
count += 1

html += "</table>"
print(html)
20 changes: 20 additions & 0 deletions Tools/csv_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import csv
import json

data = []
keys = []
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
count = 1
for row in csv_data:
if count == 1:
for y in row:
keys.append(y)
else:
element = {}
for y in range(len(row)):
element[keys[y]] = row[y]
data.append(element)
count = count+1

print(json.dumps(data,))
15 changes: 15 additions & 0 deletions Tools/csv_to_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# program to convert CSV file into PDF file
from fpdf import FPDF
import csv

with open("e:/python/tools/SampleData.csv", "r") as csv_file:
data = csv.reader(csv_file)
for row in data:
print(row)


pdf = FPDF(orientation='P', unit='mm', format='A4') # P -potrait L-Landscape
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt=str(d), ln=1, align="C")
pdf.output("simple_demo.pdf")
23 changes: 23 additions & 0 deletions Tools/csv_to_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# python program to convert any csv file into xml file
# made by : rakesh kumar

import csv
xml = '<?xml version= "1.0" encoding="UTF-8" ?><rows>'
keys = []
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
count = 1
for row in csv_data:

if count == 1:
for y in row:
keys.append(y)
else:
xml += "<row>"
for y in range(len(row)):
xml += "<"+keys[y]+">"+row[y]+"</"+keys[y]+">"
xml += "</row>"
count += 1

xml += "</rows>"
print(xml)
11 changes: 11 additions & 0 deletions Tools/html_beautifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from yattag import indent
with open("E:/python/Tools/index.html", "r") as file:
data = file.read()

result = indent(
data,
indentation=' ',
newline='\r\n',
indent_text=True
)
print(result)
1 change: 1 addition & 0 deletions Tools/sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version= "1.0" encoding="UTF-8" ?><rows><row><Rank>1</Rank><Name>Wii Sports</Name><Platform>Wii</Platform><Year>2006</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>41.49</NA_Sales><EU_Sales>29.02</EU_Sales><JP_Sales>3.77</JP_Sales><Other_Sales>8.46</Other_Sales><Global_Sales>82.74</Global_Sales></row><row><Rank>2</Rank><Name>Super Mario Bros.</Name><Platform>NES</Platform><Year>1985</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>29.08</NA_Sales><EU_Sales>3.58</EU_Sales><JP_Sales>6.81</JP_Sales><Other_Sales>0.77</Other_Sales><Global_Sales>40.24</Global_Sales></row><row><Rank>3</Rank><Name>Mario Kart Wii</Name><Platform>Wii</Platform><Year>2008</Year><Genre>Racing</Genre><Publisher>Nintendo</Publisher><NA_Sales>15.85</NA_Sales><EU_Sales>12.88</EU_Sales><JP_Sales>3.79</JP_Sales><Other_Sales>3.31</Other_Sales><Global_Sales>35.82</Global_Sales></row><row><Rank>4</Rank><Name>Wii Sports Resort</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>15.75</NA_Sales><EU_Sales>11.01</EU_Sales><JP_Sales>3.28</JP_Sales><Other_Sales>2.96</Other_Sales><Global_Sales>33</Global_Sales></row><row><Rank>5</Rank><Name>Pokemon Red/Pokemon Blue</Name><Platform>GB</Platform><Year>1996</Year><Genre>Role-Playing</Genre><Publisher>Nintendo</Publisher><NA_Sales>11.27</NA_Sales><EU_Sales>8.89</EU_Sales><JP_Sales>10.22</JP_Sales><Other_Sales>1</Other_Sales><Global_Sales>31.37</Global_Sales></row><row><Rank>6</Rank><Name>Tetris</Name><Platform>GB</Platform><Year>1989</Year><Genre>Puzzle</Genre><Publisher>Nintendo</Publisher><NA_Sales>23.2</NA_Sales><EU_Sales>2.26</EU_Sales><JP_Sales>4.22</JP_Sales><Other_Sales>0.58</Other_Sales><Global_Sales>30.26</Global_Sales></row><row><Rank>7</Rank><Name>New Super Mario Bros.</Name><Platform>DS</Platform><Year>2006</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>11.38</NA_Sales><EU_Sales>9.23</EU_Sales><JP_Sales>6.5</JP_Sales><Other_Sales>2.9</Other_Sales><Global_Sales>30.01</Global_Sales></row><row><Rank>8</Rank><Name>Wii Play</Name><Platform>Wii</Platform><Year>2006</Year><Genre>Misc</Genre><Publisher>Nintendo</Publisher><NA_Sales>14.03</NA_Sales><EU_Sales>9.2</EU_Sales><JP_Sales>2.93</JP_Sales><Other_Sales>2.85</Other_Sales><Global_Sales>29.02</Global_Sales></row><row><Rank>9</Rank><Name>New Super Mario Bros. Wii</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>14.59</NA_Sales><EU_Sales>7.06</EU_Sales><JP_Sales>4.7</JP_Sales><Other_Sales>2.26</Other_Sales><Global_Sales>28.62</Global_Sales></row><row><Rank>10</Rank><Name>Duck Hunt</Name><Platform>NES</Platform><Year>1984</Year><Genre>Shooter</Genre><Publisher>Nintendo</Publisher><NA_Sales>26.93</NA_Sales><EU_Sales>0.63</EU_Sales><JP_Sales>0.28</JP_Sales><Other_Sales>0.47</Other_Sales><Global_Sales>28.31</Global_Sales></row><row><Rank>11</Rank><Name>Nintendogs</Name><Platform>DS</Platform><Year>2005</Year><Genre>Simulation</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.07</NA_Sales><EU_Sales>11</EU_Sales><JP_Sales>1.93</JP_Sales><Other_Sales>2.75</Other_Sales><Global_Sales>24.76</Global_Sales></row><row><Rank>12</Rank><Name>Mario Kart DS</Name><Platform>DS</Platform><Year>2005</Year><Genre>Racing</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.81</NA_Sales><EU_Sales>7.57</EU_Sales><JP_Sales>4.13</JP_Sales><Other_Sales>1.92</Other_Sales><Global_Sales>23.42</Global_Sales></row><row><Rank>13</Rank><Name>Pokemon Gold/Pokemon Silver</Name><Platform>GB</Platform><Year>1999</Year><Genre>Role-Playing</Genre><Publisher>Nintendo</Publisher><NA_Sales>9</NA_Sales><EU_Sales>6.18</EU_Sales><JP_Sales>7.2</JP_Sales><Other_Sales>0.71</Other_Sales><Global_Sales>23.1</Global_Sales></row><row><Rank>14</Rank><Name>Wii Fit</Name><Platform>Wii</Platform><Year>2007</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>8.94</NA_Sales><EU_Sales>8.03</EU_Sales><JP_Sales>3.6</JP_Sales><Other_Sales>2.15</Other_Sales><Global_Sales>22.72</Global_Sales></row><row><Rank>15</Rank><Name>Wii Fit Plus</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.09</NA_Sales><EU_Sales>8.59</EU_Sales><JP_Sales>2.53</JP_Sales><Other_Sales>1.79</Other_Sales><Global_Sales>22</Global_Sales></row></rows>
2 changes: 2 additions & 0 deletions Tools/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.underline {position: relative; margin-bottom:30px;}
.underline::after{ display: block; content: ''; width: 50px; height: 1px; background: #F27316; position: absolute;bottom: -15px;left: 0%;margin-bottom: ;}
21 changes: 21 additions & 0 deletions Tools/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# python program to convert any csv file into html file
# made by : rakesh kumar

import csv
html = "<table>"
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
count = 1
for row in csv_data:
html += "<tr>"
if count == 1:
for y in row:
html += "<th>"+y+"</th>"
else:
for y in row:
html += "<td>"+y+"</td>"
html += "</tr>"
count += 1

html += "</table>"
print(html)
11 changes: 11 additions & 0 deletions Tools/xml_beatifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from yattag import indent
with open("E:/python/Tools/sample.xml", "r") as file:
data = file.read()

result = indent(
data,
indentation=' ',
newline='\r\n',
indent_text=True
)
print(result)
3 changes: 3 additions & 0 deletions dictionary/dict_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

d1 = {"name": "rakesh"}
print(d1)
21 changes: 21 additions & 0 deletions dictionary/frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
L = ['the', 'in', 'out', 'the', 'in', 'ram', 'umesh', 'the']
d = {}

""" l = len(L)
for i in range(0, l):
key = L.count(L[i])
if key not in d:
value = []
for j in range(i, l):
if(L.count(L[j]) == key and L[j] not in value):
value.append(L[j])
d[key] = value
"""

for i in L:
c = L.count(i)
if c not in d:
d[c] = [i]
elif i not in d[c]:
d[c].append(i)
print(d)
41 changes: 41 additions & 0 deletions fileHandling/commentor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# program to add comment at the begining of each python file having extension .py
# made by : rakesh kumar
# licence : MIT

import os
import sys # module for terminating
import glob
import tkinter as tk
from tkinter import filedialog

str = "# program to comment on every file \n"
str = str + "# made by : rakesh kumar \n"
str = str+" # class - : xi A \n"
str = str+" # session :2019-20 \n\n"


def add_comment(filename):
with open(filename, "r") as f:
data = f.read()

with open("abc.txt", "w") as f:
f.write(str)
f.write(data)

os.unlink(filename)
os.rename("abc.txt", filename)


if __name__ == "__main__":
root = tk.Tk()
root.withdraw()
directory = filedialog.askdirectory() # source folder
count = 0
for root, SubFolders, files in os.walk(directory):
os.chdir(root)
files = glob.glob('*.py')
# print(files)
for filename in files:
print(filename, 'Comment Added')
add_comment(filename)
count += 1
27 changes: 12 additions & 15 deletions fileHandling/csv_to_json_converter.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import csv
import json
with open(r'C:/Users/rakesh\Desktop/python/fileHandling/convert.csv') as csf_file:
with open('e:/python/tools/SampleData.csv') as csf_file:
csv_reader = csv.reader(csf_file)
line=0
keys=[]
jon=[]
line = 0
keys = []
jon = []
for row in csv_reader:
d = {}
if line==0:
if line == 0:
for col in row:
keys.append(col)
else:
for i in range(len(row)):
d[keys[i]]=row[i]

if(line>=1):
jon.append(d)
line+=1
#print(jon)

with open("jsonFile.json","w") as json_file:
json_file.write( json.dumps(jon,))
d[keys[i]] = row[i]

if(line >= 1):
jon.append(d)
line += 1
# print(jon)


with open("jsonFile.json", "w") as json_file:
json_file.write(json.dumps(jon,))
13 changes: 11 additions & 2 deletions json/import_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import json
import requests
source = requests.get('https://jsonplaceholder.typicode.com/todos/1')
print(source.read())
url = ('https://newsapi.org/v2/top-headlines?'
'country=in&'
'apiKey=2121032f088e4370affe13ca317f8d1a')
response = requests.get(url)

#source = requests.get('https://jsonplaceholder.typicode.com/todos/1')
data = json.loads(response.text)

for article in data['articles']:
print(article['author'], end="-")
print(article['title'])
2 changes: 1 addition & 1 deletion jsonFile.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"album": "The White Stripes", " year": "1999", " US_peak_chart_post": " -"}, {"album": "De Stijl", " year": "2000", " US_peak_chart_post": " -"}, {"album": "White Blood Cells", " year": "20.01", " US_peak_chart_post": "61"}, {"album": "Elephant", " year": "2003", " US_peak_chart_post": "6"}, {"album": "Get Behind Me Satan", " year": "2005", " US_peak_chart_post": "3"}, {"album": "Icky Thump", " year": "2007", " US_peak_chart_post": "2"}, {"album": "Under Great White Northern Lights", " year": "2010", " US_peak_chart_post": "11"}, {"album": "Live in Mississippi", " year": "2011", " US_peak_chart_post": " -"}, {"album": "Live at the Gold Dollar", " year": "2012", " US_peak_chart_post": " -"}, {"album": "Nine Miles from the White City", " year": "2013", " US_peak_chart_post": " -"}]
[{"Rank": "1", "Name": "Wii Sports", "Platform": "Wii", "Year": "2006", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "41.49", "EU_Sales": "29.02", "JP_Sales": "3.77", "Other_Sales": "8.46", "Global_Sales": "82.74"}, {"Rank": "2", "Name": "Super Mario Bros.", "Platform": "NES", "Year": "1985", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "29.08", "EU_Sales": "3.58", "JP_Sales": "6.81", "Other_Sales": "0.77", "Global_Sales": "40.24"}, {"Rank": "3", "Name": "Mario Kart Wii", "Platform": "Wii", "Year": "2008", "Genre": "Racing", "Publisher": "Nintendo", "NA_Sales": "15.85", "EU_Sales": "12.88", "JP_Sales": "3.79", "Other_Sales": "3.31", "Global_Sales": "35.82"}, {"Rank": "4", "Name": "Wii Sports Resort", "Platform": "Wii", "Year": "2009", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "15.75", "EU_Sales": "11.01", "JP_Sales": "3.28", "Other_Sales": "2.96", "Global_Sales": "33"}, {"Rank": "5", "Name": "Pokemon Red/Pokemon Blue", "Platform": "GB", "Year": "1996", "Genre": "Role-Playing", "Publisher": "Nintendo", "NA_Sales": "11.27", "EU_Sales": "8.89", "JP_Sales": "10.22", "Other_Sales": "1", "Global_Sales": "31.37"}, {"Rank": "6", "Name": "Tetris", "Platform": "GB", "Year": "1989", "Genre": "Puzzle", "Publisher": "Nintendo", "NA_Sales": "23.2", "EU_Sales": "2.26", "JP_Sales": "4.22", "Other_Sales": "0.58", "Global_Sales": "30.26"}, {"Rank": "7", "Name": "New Super Mario Bros.", "Platform": "DS", "Year": "2006", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "11.38", "EU_Sales": "9.23", "JP_Sales": "6.5", "Other_Sales": "2.9", "Global_Sales": "30.01"}, {"Rank": "8", "Name": "Wii Play", "Platform": "Wii", "Year": "2006", "Genre": "Misc", "Publisher": "Nintendo", "NA_Sales": "14.03", "EU_Sales": "9.2", "JP_Sales": "2.93", "Other_Sales": "2.85", "Global_Sales": "29.02"}, {"Rank": "9", "Name": "New Super Mario Bros. Wii", "Platform": "Wii", "Year": "2009", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "14.59", "EU_Sales": "7.06", "JP_Sales": "4.7", "Other_Sales": "2.26", "Global_Sales": "28.62"}, {"Rank": "10", "Name": "Duck Hunt", "Platform": "NES", "Year": "1984", "Genre": "Shooter", "Publisher": "Nintendo", "NA_Sales": "26.93", "EU_Sales": "0.63", "JP_Sales": "0.28", "Other_Sales": "0.47", "Global_Sales": "28.31"}, {"Rank": "11", "Name": "Nintendogs", "Platform": "DS", "Year": "2005", "Genre": "Simulation", "Publisher": "Nintendo", "NA_Sales": "9.07", "EU_Sales": "11", "JP_Sales": "1.93", "Other_Sales": "2.75", "Global_Sales": "24.76"}, {"Rank": "12", "Name": "Mario Kart DS", "Platform": "DS", "Year": "2005", "Genre": "Racing", "Publisher": "Nintendo", "NA_Sales": "9.81", "EU_Sales": "7.57", "JP_Sales": "4.13", "Other_Sales": "1.92", "Global_Sales": "23.42"}, {"Rank": "13", "Name": "Pokemon Gold/Pokemon Silver", "Platform": "GB", "Year": "1999", "Genre": "Role-Playing", "Publisher": "Nintendo", "NA_Sales": "9", "EU_Sales": "6.18", "JP_Sales": "7.2", "Other_Sales": "0.71", "Global_Sales": "23.1"}, {"Rank": "14", "Name": "Wii Fit", "Platform": "Wii", "Year": "2007", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "8.94", "EU_Sales": "8.03", "JP_Sales": "3.6", "Other_Sales": "2.15", "Global_Sales": "22.72"}, {"Rank": "15", "Name": "Wii Fit Plus", "Platform": "Wii", "Year": "2009", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "9.09", "EU_Sales": "8.59", "JP_Sales": "2.53", "Other_Sales": "1.79", "Global_Sales": "22"}]
6 changes: 5 additions & 1 deletion webscraper/youtubeDownloader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import unicode_literals
import youtube_dl
# import urllib
# import shutil
# import shutil
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
<<<<<<< HEAD
ydl.download(['https://www.youtube.com/watch?v=wF_B_aagLfI'])
=======
ydl.download(
['https://www.youtube.com/watch?v=SCoGwHCNXVw'])
>>>>>>> 4862d6baee53c91054712373dd7190e101b83a22

0 comments on commit dc208a4

Please sign in to comment.