diff --git a/Streaming Tweets from Twitter to Database.py b/Streaming Tweets from Twitter to Database.py deleted file mode 100644 index d418fb42315..00000000000 --- a/Streaming Tweets from Twitter to Database.py +++ /dev/null @@ -1,48 +0,0 @@ -import json -import time - -import MySQLdb -from tweepy import OAuthHandler -from tweepy import Stream -from tweepy.streaming import StreamListener - -# replace mysql.server with "localhost" if you are running via your own server! -# server MySQL username MySQL pass Database name. -conn = MySQLdb.connect("mysql.server", "beginneraccount", "cookies", "beginneraccount$tutorial") - -c = conn.cursor() - -# consumer key, consumer secret, access token, access secret. -ckey = "asdfsafsafsaf" -csecret = "asdfasdfsadfsa" -atoken = "asdfsadfsafsaf-asdfsaf" -asecret = "asdfsadfsadfsadfsadfsad" - - -class listener(StreamListener): - - def on_data(self, data): - all_data = json.loads(data) - - tweet = all_data["text"] - - username = all_data["user"]["screen_name"] - - c.execute("INSERT INTO taula (time, username, tweet) VALUES (%s,%s,%s)", - (time.time(), username, tweet)) - - conn.commit() - - print((username, tweet)) - - return True - - def on_error(self, status): - print(status) - - -auth = OAuthHandler(ckey, csecret) -auth.set_access_token(atoken, asecret) - -twitterStream = Stream(auth, listener()) -twitterStream.filter(track=["car"]) diff --git a/Tic-Tac-Toe_human_vs_human.py b/Tic-Tac-Toe_human_vs_human.py deleted file mode 100644 index a92296fea3d..00000000000 --- a/Tic-Tac-Toe_human_vs_human.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -author: shreyansh kushwaha -made on : 08.09.2020 -""" -board = {'1' : ' ','2' : ' ','3' : ' ','4' : ' ','5' : ' ','6' : ' ','7' : ' ','8' : ' ','9' : ' '} -import random, os, check, time -p1 = input("Enter your name player 1 (symbol X):\n") -p2 = input("Enter your name player 2 (symbol O):\n") -score1, score2, score_tie = [], [], [] -total_moves =0 -player = random.randint(1, 2) -time.sleep(2.6) -os.system("cls") -if player == 1: - print(f" {p1} won the toss.") -else: - print(f" {p2} won the toss") -time.sleep(3) -print(" Let us begin") -time.sleep(2) -def toggaleplayer(player): - if player == 1: - player = 2 - elif player == 2: - player = 1 -def playagain(): - inp = input("Do you want to play again??(Y/N)\n") - if inp.upper() == "Y": - a = toggaleplayer(player) - restart(a) - elif inp.upper() == "N": - os.system("cls") - print("Thanks for playing") - print(f"Number of times {p1} won : {len(score1)}.") - print(f"Number of times {p2} won : {len(score2)}.") - print(f"Number of ties: {len(score_tie)}.") - abc = input() - quit() - else: - print("Invalid input") - quit() -def restart(a): - total_moves, board =0, {'1' : ' ','2' : ' ','3' : ' ','4' : ' ','5' : ' ','6' : ' ','7' : ' ','8' : ' ','9' : ' '} - while True: - os.system("cls") - print(board['1'] + '|' + board['2'] + '|' + board['3'] ) - print('-+-+-') - print(board['4'] + '|' + board['5'] + '|' + board['6'] ) - print('-+-+-') - print(board['7'] + '|' + board['8'] + '|' + board['9'] ) - check.check(total_moves,score1, score2, score_tie, playagain, board, p1, p2) - while True: - if a == 1: - p1_input = input(f"Its {p1}'s chance..\nwhere do you want to place your move:") - if p1_input.upper() in board and board[p1_input.upper()] == " ": - board[p1_input.upper()] = 'X' - a = 2 - break - else: # on wrong input - print("Invalid input \n Enter again. ") - continue - else: - p2_input = input(f"Its {p2}'s chance..\nwhere do you want to place your move:") - if p2_input.upper() in board and board[p2_input.upper()] == " ": - board[p2_input.upper()] = 'O' - a = 1 - break - else: - print("Invalid Input") - continue - total_moves += 1 -while True: - os.system("cls") - print(board['1'] + '|' + board['2'] + '|' + board['3'] ) - print('-+-+-') - print(board['4'] + '|' + board['5'] + '|' + board['6'] ) - print('-+-+-') - print(board['7'] + '|' + board['8'] + '|' + board['9'] ) - check.check(total_moves,score1, score2, score_tie, playagain, board, p1, p2) - while True: - if player == 1: - p1_input = input(f"Its {p1}'s chance..\nwhere do you want to place your move:") - if p1_input.upper() in board and board[p1_input.upper()] == " ": - board[p1_input.upper()] = 'X' - player = 2 - break - else: # on wrong input - print("Invalid input ") - continue - else: - p2_input = input(f"Its {p2}'s chance..\nwhere do you want to place your move:") - if p2_input.upper() in board and board[p2_input.upper()] == " ": - board[p2_input.upper()] = 'O' - player = 1 - break - else: - print("Invalid Input") - continue - total_moves += 1 diff --git a/TicTacToe.py b/TicTacToe.py deleted file mode 100644 index e424444120d..00000000000 --- a/TicTacToe.py +++ /dev/null @@ -1,192 +0,0 @@ -# Tic Tac Toe - -import random - -try: - input = raw_input -except NameError: - pass - - -def drawBoard(board): - # This function prints out the board that it was passed. - - # "board" is a list of 10 strings representing the board (ignore index 0) - print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9]) - print('-----------') - print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6]) - print('-----------') - print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3]) - - -def inputPlayerLetter(): - # Lets the player type which letter they want to be. - # Returns a list with the player's letter as the first item, and the computer's letter as the second. - letter = '' - while letter not in ('X', 'O'): - letter = input('Do you want to be X or O? ').upper() - - # the first element in the tuple is the player's letter, the second is the computer's letter. - - return ['X', 'O'] if letter == 'X' else ['O', 'X'] - - -def whoGoesFirst(): - # Randomly choose the player who goes first. - return random.choice(('computer', 'player')) - - -def playAgain(): - # This function returns True if the player wants to play again, otherwise it returns False. - print('Do you want to play again? (yes or no)') - return input().lower().startswith('y') - - -def makeMove(board, letter, move): - if isSpaceFree(board, move): - board[move] = letter - else: - raise Exception("makeMove: the field is not empty!") - - -def isWinner(bo, le): - # Given a board and a player's letter, this function returns True if that player has won. - # We use bo instead of board and le instead of letter so we don't have to type as much. - return ((bo[7] == le and bo[8] == le and bo[9] == le) or # across the top - (bo[4] == le and bo[5] == le and bo[6] == le) or # across the middle - (bo[1] == le and bo[2] == le and bo[3] == le) or # across the bottom - (bo[7] == le and bo[4] == le and bo[1] == le) or # down the left side - (bo[8] == le and bo[5] == le and bo[2] == le) or # down the middle - (bo[9] == le and bo[6] == le and bo[3] == le) or # down the right side - (bo[7] == le and bo[5] == le and bo[3] == le) or # diagonal - (bo[9] == le and bo[5] == le and bo[1] == le)) # diagonal - - -def getBoardCopy(board): - # Make a duplicate of the board list and return it the duplicate. - dupeBoard = [] - - for i in board: - dupeBoard.append(i) - - return dupeBoard - - -def isSpaceFree(board, move): - # Return true if the passed move is free on the passed board. - return board[move].isdigit() - - -def getPlayerMove(board): - # Let the player type in his move. - move = ' ' - while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)): - print('What is your next move? (1-9)') - move = input() - return int(move) - - -def chooseRandomMoveFromList(board, movesList): - # Returns a valid move from the passed list on the passed board. - # Returns None if there is no valid move. - possibleMoves = [i for i in movesList if isSpaceFree(board, i)] - return random.choice(possibleMoves) if possibleMoves else None - - -def getComputerMove(board, computerLetter): - # Given a board and the computer's letter, determine where to move and return that move. - playerLetter = 'O' if computerLetter == 'X' else 'X' - - # Here is our algorithm for our Tic Tac Toe AI: - # First, check if we can win in the next move - for i in range(1, 10): - copy = getBoardCopy(board) - if isSpaceFree(copy, i): - makeMove(copy, computerLetter, i) - if isWinner(copy, computerLetter): - return i - - # Check if the player could win on his next move, and block them. - for i in range(1, 10): - copy = getBoardCopy(board) - if isSpaceFree(copy, i): - makeMove(copy, playerLetter, i) - if isWinner(copy, playerLetter): - return i - - # Try to take one of the corners, if they are free. - move = chooseRandomMoveFromList(board, [1, 3, 7, 9]) - if move != None: - return move - - # Try to take the center, if it is free. - if isSpaceFree(board, 5): - return 5 - - # Move on one of the sides. - return chooseRandomMoveFromList(board, [2, 4, 6, 8]) - - -def isBoardFull(board): - # Return True if every space on the board has been taken. Otherwise return False. - for i in range(1, 10): - if isSpaceFree(board, i): - return False - return True - - -def main(): - print('Welcome to Tic Tac Toe!') - random.seed() - while True: - # Reset the board - theBoard = [' '] * 10 - for i in range(9, 0, -1): - theBoard[i] = str(i) - playerLetter, computerLetter = inputPlayerLetter() - turn = whoGoesFirst() - print('The ' + turn + ' will go first.') - gameIsPlaying = True - - while gameIsPlaying: - if turn == 'player': - # Player's turn. - drawBoard(theBoard) - move = getPlayerMove(theBoard) - makeMove(theBoard, playerLetter, move) - - if isWinner(theBoard, playerLetter): - drawBoard(theBoard) - print('Hooray! You have won the game!') - gameIsPlaying = False - else: - if isBoardFull(theBoard): - drawBoard(theBoard) - print('The game is a tie!') - break - else: - turn = 'computer' - - else: - # Computer's turn. - move = getComputerMove(theBoard, computerLetter) - makeMove(theBoard, computerLetter, move) - - if isWinner(theBoard, computerLetter): - drawBoard(theBoard) - print('The computer has beaten you! You lose.') - gameIsPlaying = False - else: - if isBoardFull(theBoard): - drawBoard(theBoard) - print('The game is a tie!') - break - else: - turn = 'player' - - if not playAgain(): - break - - -if __name__ == "__main__": - main() diff --git a/count_vowels.py b/count_vowels.py index d2b309de9c1..ed35c4c4a8c 100644 --- a/count_vowels.py +++ b/count_vowels.py @@ -15,5 +15,5 @@ else: consonant_count +=1 -print "Total Vowels ", vowel_count -print "Total consonant ", consonant_count +print ("Total Vowels: ", vowel_count) +print ("Total consonants: ", consonant_count) diff --git a/json_to_table.py b/json_to_table.py deleted file mode 100644 index 50b83c30e07..00000000000 --- a/json_to_table.py +++ /dev/null @@ -1,8 +0,0 @@ -import json -import pandas as pd -# //jsondata is a collection of data in json format - -# //Used panndas dataframe to convert json data to dataframes table -jdata = json.loads(jsondata) -df = pd.DataFrame(jdata) -# //print(df.T) diff --git a/railwayreservation.py b/railwayreservation.py deleted file mode 100644 index 712e3efb7a5..00000000000 --- a/railwayreservation.py +++ /dev/null @@ -1,166 +0,0 @@ -import mysql.connector -import os -import platform -import pandas as pd -pnr=1024 -mydb=mysql.connector.connect(host="localhost",user="RAM KUMAR VERMA",passwd="RAM",database="rail"); -mycursor=mydb.cursor() -def railresmenu(): - print("Railway Reservation ") - print("1.Train Detail") - print("2.Reservation of Ticket") - print("3.Cancellation of Ticket") - print("4.Display PNR status") - print("5.Quit") - - n=int(input("enter your choice")) - if(n==1): - traindetail() - elif(n==2): - reservation() - elif(n==3): - cancel() - elif(n==4): - displayPNR() - elif(n==5): - exit(0) - else: - print("wrong choice") - - -def traindetail(): - print("Train Details") - ch='y' - while (ch=='y'): - l=[] - name=input("enter train name :") - l.append(name) - tnum=int(input("enter train number :")) - l.append(tnum) - ac1=int(input("enter number of AC 1 class seats")) - l.append(ac1) - ac2=int(input("enter number of AC 2 class seats")) - l.append(ac2) - ac3=int(input("enter number of AC 3 class seats")) - l.append(ac3) - slp=int(input("enter number of sleeper class seats")) - l.append(slp) - train=(l) - sql="insert into traindetail(tname,tnum,ac1,ac2,ac3,slp)values(%s,%s,%s,%s,%s,%s)" - mycursor.execute(sql,train) - mydb.commit() - print("insertion completed") - print("Do you want to insert more train Detail") - ch=input("enter yes/no") - print('\n' *10) - - print("===================================================================") - railresmenu() -def reservation(): - global pnr - l1=[] - pname=input("enter passenger name=") - l1.append(pname) - age=input("enter age of passenger =") - l1.append(age) - trainno=input("enter train number") - l1.append(trainno) - np=int(input("Enter number of passanger:")) - l1.append(np) - print("select a class you would like to travel in") - print("1.AC FIRST CLASS") - print("2.AC SECOND CLASS") - print("3.AC THIRD CLASS") - print("4.SLEEPER CLASS") - cp=int(input("Enter your choice:")) - if(cp==1): - amount=np*1000 - cls='ac1' - elif(cp==2): - amount=np*800 - cls='ac2' - elif(cp==3): - amount=np*500 - cls='ac3' - else: - amount=np*350 - cls='slp' - l1.append(cls) - print("Total amount to be paid:",amount) - l1.append(amount) - pnr=pnr+1 - print("PNR Number:",pnr) - print("status: confirmed") - sts='conf' - l1.append(sts) - l1.append(pnr) - train1=(l1) - sql="insert into passengers(pname,age,trainno,noofpas,cls,amt,status,pnrno)values(%s,%s,%s,%s,%s,%s,%s,%s)" - mycursor.execute(sql,train1) - mydb.commit() - print("insertion completed") - print("Go back to menu") - print('\n' *10) - - print("===================================================================") - railresmenu() - railresmenu() -def cancel(): - print("Ticket cancel window") - pnr=input("enter PNR for cancellation of Ticket") - pn=(pnr,) - sql="update passengers set status='deleted' where pnrno=%s" - mycursor.execute(sql,pn) - mydb.commit() - print("Deletion completed") - print("Go back to menu") - print('\n' *10) - - print("===================================================================") - railresmenu() - railresmenu() -def displayPNR(): - print("PNR STATUS window") - pnr=input("enter PNR NUMBER") - pn=(pnr,) - sql="select * from passengers where pnrno=%s" - mycursor.execute(sql,pn) - res=mycursor.fetchall() - #mydb.commit() - print("PNR STATUS are as follows : ") - print("(pname,age,trainno, noofpas,cls,amt,status, pnrno)") - for x in res: - print(x) - #print("Deletion completed") - print("Go back to menu") - print('\n' *10) - - print("===================================================================") - railresmenu() - railresmenu() - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/site_health.py b/site_health.py deleted file mode 100644 index 857c487f1fb..00000000000 --- a/site_health.py +++ /dev/null @@ -1,108 +0,0 @@ -#! /usr/bin/env python -"""This script is very useful for when you just to do a health check on a remote server. It does the followings: - - NSLOOKUP - - PING to see if the site is up - - Certificate/SSL/TLS info """ -import hashlib -import os -from urllib.error import URLError, HTTPError -from urllib.request import Request, urlopen, ssl, socket - - -class ServerHealthCheck(): - - def __init__(self, base_url, port, tcp): - self.base_url = base_url - self.ip_now = self.obtain_ip() - self.port = port - self.tcp = tcp - self.url_path = self.tcp + "://" + base_url - self.ping_host() - self.obtain_http_info() - self.obtain_cert_info() - - def obtain_ip(self): - print("__LOOKUP____________________________________________") - currnet_ip = socket.gethostbyname(self.base_url) - print("ip: " + currnet_ip) - print("FQDN: " + socket.getfqdn(self.base_url)) - distinct_ips = [] - # 0,0,0,0 is for (family, type, proto, canonname, sockaddr) - socket_info = socket.getaddrinfo(self.base_url, 0, 0, 0, 0) - for result in socket_info: - ns_ip = result[4][0] - if distinct_ips.count(ns_ip) == 0: - distinct_ips.append(ns_ip) - print(ns_ip) - distinct_ips = list(set(distinct_ips)) - return currnet_ip - - def ping_host(self): - # ping reesult - print("\n\n" + "__PING INFO____________________________________________") - response = os.system("ping -c 1 " + self.ip_now) - # and then check the response... - if response == 0: - print("server " + self.base_url + ": is up ") - else: - print("server " + self.base_url + ": is DOWN !!!") - - def obtain_http_info(self): - print("__SSL/TLS INFO____________________________________________") - req = Request(self.url_path) - try: - response = urlopen(req, context=ssl._create_unverified_context()) - # htmlSource = response.read() - except HTTPError as e: - print('The server couldn\'t fulfill the request.') - print('Error code: ', e.code) - except URLError as e: - print('We failed to reach a server.') - print('Reason: ', e.reason) - else: - print("http code:" + str(response.getcode())) - - def obtain_cert_info(self): - context = ssl.create_default_context() - with socket.create_connection((self.base_url, self.port)) as socket_connection: - with context.wrap_socket(socket_connection, server_hostname=self.base_url) as server_socket: - # uncomment to print everything - # print(json.dumps(server_socket.getpeercert() , indent=2, sort_keys=True)) - cert_info = server_socket.getpeercert() - subject = dict(x[0] for x in cert_info['subject']) - issued_to = subject['commonName'] - issuer = dict(x[0] for x in cert_info['issuer']) - issued_by = issuer['commonName'] - valid_from = cert_info['notBefore'] - valid_to = cert_info['notAfter'] - serial_number = cert_info['serialNumber'] - der_cert = server_socket.getpeercert(False) - der_cert_bin = server_socket.getpeercert(True) - pem_cert = ssl.DER_cert_to_PEM_cert(server_socket.getpeercert(True)) - # uncomment the below line if you want to see the actual public cert - # print("certificate pub:",pem_cert) - thumb_md5 = hashlib.md5(der_cert_bin).hexdigest() - thumb_sha1 = hashlib.sha1(der_cert_bin).hexdigest() - thumb_sha256 = hashlib.sha256(der_cert_bin).hexdigest() - print("issued_to: " + issued_to) - print("issued_by: " + issued_by) - print("valid_from: " + valid_from) - print("valid_to: " + valid_from) - print("MD5: " + thumb_md5) - print("SHA1: " + thumb_sha1) - print("SHA256: " + thumb_sha256) - print("cipher: " + str(server_socket.cipher())) - print("SSL/TLS version: " + server_socket.version()) - print("serial_number: " + serial_number) - # print(server_socket.shared_ciphers()) - server_socket.close() - - -if __name__ == '__main__': - # DO NOT USE IP - - host_name = input("host name ? (example github.com) \n") - - prt = input("port ? \n") - tcp_it = "https" - serverHealthCheck = ServerHealthCheck(host_name, prt, tcp_it) diff --git a/spotlight.py b/spotlight.py deleted file mode 100644 index 8da2336e55e..00000000000 --- a/spotlight.py +++ /dev/null @@ -1,75 +0,0 @@ -""" Script To Copy Spotlight(Lockscreen) Images from Windows """ -from __future__ import print_function - -import errno -import hashlib -import os -import shutil - -from PIL import Image - -try: - input = raw_input -except NameError: - pass - - -def md5(fname): - """ Function to return the MD5 Digest of a file """ - - hash_md5 = hashlib.md5() - with open(fname, "rb") as file_var: - for chunk in iter(lambda: file_var.read(4096), b""): - hash_md5.update(chunk) - return hash_md5.hexdigest() - - -def make_folder(folder_name): - """Function to make the required folers""" - try: - os.makedirs(folder_name) - except OSError as exc: - if exc.errno == errno.EEXIST and os.path.isdir(folder_name): - pass - else: - print("Error! Could not create a folder") - raise - - -def get_spotlight_wallpapers(target_folder): - """Fetches wallpapers from source folder inside AppData to the - newly created folders in C:\\Users\\['user.name']\\Pictures""" - # PATHS REQUIRED TO FETCH AND STORE WALLPAPERS - # Creating necessary folders - - source_folder = os.environ['HOME'] + "\\AppData\\Local\\Packages\\" - source_folder += "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy" - source_folder += "\\LocalState\\Assets" - spotlight_path_mobile = target_folder + "\\Mobile" - spotlight_path_desktop = target_folder + "\\Desktop" - make_folder(spotlight_path_mobile) - make_folder(spotlight_path_desktop) - - # Fetching files from the source dir - for filename in os.listdir(source_folder): - filename = source_folder + "\\" + filename - # if size of file is less than 100 KB, ignore the file - if os.stat(filename).st_size > 100000: - # Check resolution and classify based upon the resolution of the images - - # name the file equal to the MD5 of the file, so that no duplicate files are to be copied - img_file = Image.open(filename) - if img_file.size[0] >= 1080: - if img_file.size[0] > img_file.size[1]: - temp_path = spotlight_path_desktop + "\\" + md5(filename) - else: - temp_path = spotlight_path_mobile + "\\" + md5(filename) - # If file doesn't exist, copy the file to the new folders - if not os.path.exists(temp_path + ".png"): - shutil.copy(filename, temp_path + ".png") - - -if __name__ == '__main__': - PATH = input("Enter directory path:").strip() - get_spotlight_wallpapers(PATH) - print("Lockscreen images have been copied to \"" + PATH + "\"") diff --git a/start-server.py b/start-server.py deleted file mode 100644 index 010b72cf6ad..00000000000 --- a/start-server.py +++ /dev/null @@ -1,13 +0,0 @@ -from __future__ import print_function - -import SimpleHTTPServer -import SocketServer - -PORT = 8000 # This will serve at port 8080 - -Handler = SimpleHTTPServer.SimpleHTTPRequestHandler - -httpd = SocketServer.TCPServer(("", PORT), Handler) - -print("serving at port", PORT) -httpd.serve_forever() diff --git a/tar.py b/tar.py deleted file mode 100644 index d64cd0ba524..00000000000 --- a/tar.py +++ /dev/null @@ -1,69 +0,0 @@ -import gzip -import os -import rarfile -import tarfile -import zipfile - -from library.utils.file import get_filetype -from library.utils.path import make_dir - - -def uncompress(src_file, dest_dir): - result = get_filetype(src_file) - if not result[0]: - return (False, result[1], '') - filefmt = result[1] - - result = make_dir(dest_dir) - if not result: - return (False, '创建解压目录失败', filefmt) - - if filefmt in ('tgz', 'tar'): - try: - tar = tarfile.open(src_file) - names = tar.getnames() - for name in names: - tar.extract(name, dest_dir) - tar.close() - except Exception as e: - return (False, e, filefmt) - elif filefmt == 'zip': - try: - zip_file = zipfile.ZipFile(src_file) - for names in zip_file.namelist(): - zip_file.extract(names, dest_dir) - zip_file.close() - except Exception as e: - return (False, e, filefmt) - elif filefmt == 'rar': - try: - rar = rarfile.RarFile(src_file) - os.chdir(dest_dir) - rar.extractall() - rar.close() - except Exception as e: - return (False, e, filefmt) - elif filefmt == 'gz': - try: - - f_name = dest_dir + '/' + os.path.basename(src_file) - # 获取文件的名称,去掉 - g_file = gzip.GzipFile(src_file) - # 创建gzip对象 - open(f_name, "w+").write(g_file.read()) - # gzip对象用read()打开后,写入open()建立的文件中。 - g_file.close() - # 关闭gzip对象 - - result = get_filetype(src_file) - if not result[0]: - new_filefmt = '未知' - else: - new_filefmt = result[1] - return (True, '解压后的文件格式为:' + new_filefmt, filefmt) - except Exception as e: - return (False, e, filefmt) - else: - return (False, '文件格式不支持或者不是压缩文件', filefmt) - - return (True, '', filefmt) diff --git a/text_cleaning_comparisson.py b/text_cleaning_comparisson.py deleted file mode 100644 index 9b70d83303b..00000000000 --- a/text_cleaning_comparisson.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# In[63]: - - -from re import sub, compile -from string import punctuation -from time import process_time - -import pandas as pd -from nltk.corpus import stopwords, gutenberg -from nltk.tokenize import sent_tokenize -from sklearn.feature_extraction.text import CountVectorizer -from unidecode import unidecode - -# Data for testing -emma = gutenberg.words('austen-emma.txt') -example_text = ' '.join(emma) -df = pd.DataFrame(data={'sentences': sent_tokenize(example_text)}) -tokenizer = lambda s: clean_text(s).split() - -vectorizer = CountVectorizer(encoding='ascii', decode_error='ignore', - strip_accents='ascii', - tokenizer=tokenizer, lowercase=False, - max_df=0.7, - min_df=0.0001 - ) -vectorizer.fit(df['sentences']) - -STOP_WORDS = stopwords.words('english') -# Remove any charcater is non alphanumeric or space -pattern_cleaning = compile(r'[^\w\s]|\d') -pattern_stop_words = compile(r'\b(' + r'|'.join(STOP_WORDS) + r')\b\s*') -# First remove punctuation and numbers, then remove stop words -remove_punctuation_r = lambda s: sub(pattern_stop_words, '', sub(pattern_cleaning, '', s.lower())) -remove_short_words = lambda s: ' '.join(filter(lambda w: len(w) > 2, s.split())) -# Remove numbers, short words (one or two characters), -# punctuaction, non ascii characers and stop words -clean_text = lambda s: remove_short_words(remove_punctuation_r(s)) - -# Data cleaning functions - -pattern_cleaning = compile(r'[^\w\s]|\d') -pattern_stop_words = compile(r'\b(' + r'|'.join(stopwords.words('english')) + r')\b\s*') -pattern_short_words = compile(r'\b[^\s]{0,2}\b') -exclude = punctuation - -remove_punctuation_t = lambda s: unidecode(s).translate(str.maketrans('', '', exclude)).lower() -remove_punctuation_r = lambda s: sub(pattern_stop_words, '', sub(pattern_cleaning, '', s.lower())) -remove_stop_words = lambda s: ' '.join([word for word in s.split() if word not in STOP_WORDS]) -remove_stop_words_2 = lambda s: sub(pattern_stop_words, '', s) -remove_stop_words_3 = lambda s: ' '.join(filter(lambda w: len(w) > 2 and not w in STOP_WORDS, s.split())) -remove_short_words = lambda s: ' '.join(filter(lambda w: len(w) > 2, s.split())) -remove_short_words_2 = lambda s: sub(pattern_stop_words, '', s) - -clean_text_1 = lambda s: remove_short_words_2(remove_punctuation_r(s)) -clean_text_2 = lambda s: remove_short_words(remove_punctuation_r(s)) -clean_text_3 = lambda s: remove_stop_words(remove_short_words(remove_punctuation_t(s))) -clean_text_4 = lambda s: remove_stop_words_3(remove_punctuation_t(s)) -clean_text_5 = lambda s: remove_stop_words_3(remove_punctuation_r(s)) - -# Comparing data cleaning ways -func = (clean_text_1, clean_text_2, clean_text_3, clean_text_4, clean_text_5) -title = ('Regex and unidecode, loop (short words)', - 'Regex and unidecode, filter (short words)', - 'Translate and unidecode, filter (short words) ,loops (stop words)', - 'Translate and unidecode, filter (short words, stop words)', - 'Regex, loop (short words, stop words)' - ) -for f, t in zip(func, title): - print('*' * len(t)) - print(t) - print('*' * len(t)) - t0 = process_time() - print(df['sentences'].apply(f).head()) - print(f'Time: {process_time() - t0}') diff --git a/timymodule.py b/timymodule.py deleted file mode 100644 index b4a4d2d692c..00000000000 --- a/timymodule.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Written by: Shreyas Daniel - github.com/shreydan -Description: an overview of 'timy' module - pip install timy - -A great alternative to Pythons 'timeit' module and easier to use. -""" - -import timy # begin by importing timy - - -@timy.timer(ident='listcomp', loops=1) # timy decorator -def listcomprehension(): # the function whose execution time is calculated. - li = [x for x in range(0, 100000, 2)] - - -listcomprehension() - -""" -this is how the above works: - timy decorator is created. - any function underneath the timy decorator is the function whose execution time - need to be calculated. - after the function is called. The execution time is printed. - in the timy decorator: - ident: an identity for each timy decorator, handy when using a lot of them - loops: no. of times this function has to be executed -""" - - -# this can also be accomplished by 'with' statement: -# tracking points in between code can be added -# to track specific instances in the program - -def listcreator(): - with timy.Timer() as timer: - li = [] - for i in range(0, 100000, 2): - li.append(i) - if i == 50000: - timer.track('reached 50000') - - -listcreator() - -""" -there are many more aspects to 'timy' module. -check it out here: https://github.com/ramonsaraiva/timy -""" diff --git a/xkcd_downloader.py b/xkcd_downloader.py deleted file mode 100644 index 073e91c72ac..00000000000 --- a/xkcd_downloader.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Written by: Shreyas Daniel - github.com/shreydan -Written on: 26 April 2017 - -Description: Download latest XKCD Comic with this program. - -NOTE: - if this script is launched from the cloned repo, a new folder is created. - Please move the file to another directory to avoid messing with the folder structure. -""" - -import os -import urllib.request - -import requests -from lxml import html - - -def main(): - # opens xkcd.com - try: - page = requests.get("https://www.xkcd.com") - except requests.exceptions.RequestException as e: - print(e) - exit() - - # parses xkcd.com page - tree = html.fromstring(page.content) - - # finds image src url - image_src = tree.xpath(".//*[@id='comic']/img/@src")[0] - image_src = "https:" + str(image_src) - - # gets comic name from the image src url - comic_name = image_src.split('/')[-1] - - # save location of comic - comic_location = os.getcwd() + '/comics/' - - # checks if save location exists else creates - if not os.path.exists(comic_location): - os.makedirs(comic_location) - - # creates final comic location including name of the comic - comic_location = comic_location + comic_name - - # downloads the comic - urllib.request.urlretrieve(image_src, comic_location) - - -if __name__ == "__main__": - main() diff --git a/youtube-downloader fast.py b/youtube-downloader fast.py deleted file mode 100644 index 1cf00118afc..00000000000 --- a/youtube-downloader fast.py +++ /dev/null @@ -1,13 +0,0 @@ -''' -Author: Anshu Saini -GitHub: https://github.com/anshu189 -mail: anshusaini189381@gmail.com -Requirements: pytube (pip install pytube) -''' - -import pytube as py - -url = input("Enter your youtube video url: ") - -py.YouTube(url).streams.get_highest_resolution().download( - 'C:/Users/user-name/Desktop') # (PATH) Where you want to save your downloaded video diff --git a/youtube.py b/youtube.py deleted file mode 100644 index 0b14840da3b..00000000000 --- a/youtube.py +++ /dev/null @@ -1,30 +0,0 @@ -''' -Author: Anshu Saini -GitHub: https://github.com/anshu189 -mail: anshusaini189381@gmail.com -Requirements: Selenium (pip install selenium), webdriver (https://sites.google.com/a/chromium.org/chromedriver/downloads) -''' - -from selenium import webdriver -from time import sleep as s - -song_name = input("Enter your song name: ") -artist_name = input("Enter the artist name(optional): ") -add = song_name + artist_name - -link = "https://www.youtube.com/results?search_query=" + add - -driver_path = "C:/chromedriver.exe" # Your Chromedriver.exe path here - -# <---For Brave Browser---> -# brave_path = "C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe" # Your Brave.exe path here -# option = webdriver.ChromeOptions() -# option.binary_location = brave_path - -# driv = webdriver.Chrome(executable_path=driver_path, options=option) -driv = webdriver.Chrome(driver_path) - -driv.maximize_window() -driv.get(link) -s(0.5) -driv.find_element_by_xpath("//*[@id='video-title']").click()