From 0efcf03eb062bc2e0c64c3f484fa4c71eeda2723 Mon Sep 17 00:00:00 2001 From: rakesh Date: Wed, 22 Jan 2020 13:17:31 +0530 Subject: [PATCH] python tools --- Tools/SampleData.csv | 16 +++++++++++++ Tools/csv_to_html.py | 21 +++++++++++++++++ Tools/csv_to_json.py | 19 +++++++++++++++ dictionary/frequency.py | 21 +++++++++++++++++ fileHandling/commentor.py | 41 +++++++++++++++++++++++++++++++++ json/import_json.py | 13 +++++++++-- webscraper/youtubeDownloader.py | 9 ++------ 7 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 Tools/SampleData.csv create mode 100644 Tools/csv_to_html.py create mode 100644 Tools/csv_to_json.py create mode 100644 dictionary/frequency.py create mode 100644 fileHandling/commentor.py diff --git a/Tools/SampleData.csv b/Tools/SampleData.csv new file mode 100644 index 0000000..a9135a6 --- /dev/null +++ b/Tools/SampleData.csv @@ -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 \ No newline at end of file diff --git a/Tools/csv_to_html.py b/Tools/csv_to_html.py new file mode 100644 index 0000000..86b3124 --- /dev/null +++ b/Tools/csv_to_html.py @@ -0,0 +1,21 @@ +# python program to convert any csv file into html file +# made by : rakesh kumar + +import csv +html = "" +with open("E:/python/Tools/SampleData.csv") as csv_file: + csv_data = csv.reader(csv_file) + count = 1 + for row in csv_data: + html += "" + if count == 1: + for y in row: + html += "" + else: + for y in row: + html += "" + html += "" + count += 1 + +html += "
"+y+""+y+"
" +print(html) diff --git a/Tools/csv_to_json.py b/Tools/csv_to_json.py new file mode 100644 index 0000000..7e71e9a --- /dev/null +++ b/Tools/csv_to_json.py @@ -0,0 +1,19 @@ +import csv +json = [] +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] + json.append(element) + + count = count+1 + +print(json) diff --git a/dictionary/frequency.py b/dictionary/frequency.py new file mode 100644 index 0000000..1f13534 --- /dev/null +++ b/dictionary/frequency.py @@ -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) diff --git a/fileHandling/commentor.py b/fileHandling/commentor.py new file mode 100644 index 0000000..2e3bc12 --- /dev/null +++ b/fileHandling/commentor.py @@ -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 diff --git a/json/import_json.py b/json/import_json.py index cc3d0f0..c7965b1 100644 --- a/json/import_json.py +++ b/json/import_json.py @@ -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']) diff --git a/webscraper/youtubeDownloader.py b/webscraper/youtubeDownloader.py index ef6948d..42dbf79 100644 --- a/webscraper/youtubeDownloader.py +++ b/webscraper/youtubeDownloader.py @@ -1,12 +1,7 @@ from __future__ import unicode_literals import youtube_dl # import urllib -# import shutil +# import shutil ydl_opts = {} with youtube_dl.YoutubeDL(ydl_opts) as ydl: - ydl.download( -<<<<<<< HEAD - ['https://www.youtube.com/watch?v=skG_36Abhos']) -======= - ['https://www.youtube.com/watch?v=7nH2NYpeKa4&list=PLuiqR73XWRBZ7PpaADMES1LCtvzkc2MJt&index=1']) ->>>>>>> 1ddf82b2ad35dc035189900c6208296c03e16f97 + ydl.download(['https://www.youtube.com/watch?v=wF_B_aagLfI'])