From 692ea1fbbb247d0e3d5e539d30ab26ab16683e77 Mon Sep 17 00:00:00 2001 From: eazuniga Date: Thu, 3 Oct 2019 08:49:30 +0800 Subject: [PATCH 1/6] Added Find Phone Numbers in a string --- .../Find-PhoneNumber-in-String.py | 24 +++++++++++++++++++ Find-PhoneNumber-in-String/README.md | 10 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py create mode 100644 Find-PhoneNumber-in-String/README.md diff --git a/Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py b/Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py new file mode 100644 index 0000000..8ace308 --- /dev/null +++ b/Find-PhoneNumber-in-String/Find-PhoneNumber-in-String.py @@ -0,0 +1,24 @@ +def check_phone_number(string): + if len(string) != 12: + return False + for i in range(0, 3): + if not string[i].isdecimal(): + return False + if string[3] != '-': + return False + for i in range(4, 7): + if not string[i].isdecimal(): + return False + if string[7] != '-': + return False + for i in range(8, 12): + if not string[i].isdecimal(): + return False + return True + +string = input("Enter a Sentence: ") + +for i in range(len(string)): + split = string[i:i+12] + if check_phone_number(split): + print('Phone number has been found! : ' + split) \ No newline at end of file diff --git a/Find-PhoneNumber-in-String/README.md b/Find-PhoneNumber-in-String/README.md new file mode 100644 index 0000000..96418a0 --- /dev/null +++ b/Find-PhoneNumber-in-String/README.md @@ -0,0 +1,10 @@ +# Find Phone Number in a string + +A python script that will extract phone numbers in a string + +## Requirements +Python 3.7.3 + +## Usage +$ python Find-PhoneNumber-in-String.py +Enter a Sentence: Call me in this number 403-867-2229 \ No newline at end of file From 8ac09c04ff9c0808d6ecd849a6cf4e0c8b788c37 Mon Sep 17 00:00:00 2001 From: Rodolfo Ferro Date: Thu, 3 Oct 2019 03:08:43 -0500 Subject: [PATCH 2/6] Added signatue photo to (transparent) png converter script. --- README.md | 9 ++-- signature2png/README.md | 59 +++++++++++++++++++++ signature2png/imgs/example.jpg | Bin 0 -> 12176 bytes signature2png/imgs/result.png | Bin 0 -> 3299 bytes signature2png/signature.py | 90 +++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 signature2png/README.md create mode 100644 signature2png/imgs/example.jpg create mode 100644 signature2png/imgs/result.png create mode 100644 signature2png/signature.py diff --git a/README.md b/README.md index 89b4a09..cbaf68b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ So far, the following projects have been integrated to this repo: |[Gmail Mailing Script](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/mailing) |[mayank-kapur](https://github.com/kapurm17) | |[Handwrting DNN recognizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Handwriting_Recognizer) |[Chris]() | |[HTML Table to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/HTML_Table_to_List) | [Nitish Srivastava](https://github.com/nitish-iiitd)| -|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) | +|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) | |[Image To PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/images2pdf)|[msaoudallah](https://github.com/msaoudallah)| |[Instadp Web Scrapper](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/InstadpShower)|[Psychiquest](https://github.com/psychiquest)| |[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()| @@ -39,6 +39,7 @@ So far, the following projects have been integrated to this repo: |[Python Algebra Solver](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Algebra-Solver)|[Sengxay Xayachack](https://github.com/frankxayachack)| |[Random name generator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Random_Names_Generator)| [Ayush Bhardwaj](https://github.com/hastagAB)| |[Server Ping](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Ping_Server)|[prince]()| +|[Signature photo to PNG converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/signature2png)|[Rodolfo Ferro](https://github.com/RodolfoFerro)| |[Simple Webpage Parser](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/SimpleWebpageParser)|[Nitish Srivastava](https://github.com/nitish-iiitd)| |[Slideshare downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Slideshare-Downloader)|[Chris Goes](https://github.com/GhostofGoes)| |[SMS your location](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/SmsYourLocation)|[prince]()| @@ -63,14 +64,14 @@ Remember to star the repo if you love the scipts~ :wink: ## Contribuition Guidelines : - Make a **separate folder** for your script. -- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol) +- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol) - :x: Script One - :heavy_check_mark: Script_One - :heavy_check_mark: Script-One - The Folder should contain the followings - - - Main Python Script, + - Main Python Script, - Supporting files for the Script (If any) - A separate `README.md` File with proper documentation. - + - Feel Free to add your script in the [project's list](https://github.com/hastagAB/Awesome-Python-Scripts#what-do-we-have) above. diff --git a/signature2png/README.md b/signature2png/README.md new file mode 100644 index 0000000..0e5f769 --- /dev/null +++ b/signature2png/README.md @@ -0,0 +1,59 @@ +# Python signature editor + +The present repo contains a Python script to process signature images, it returns a `png` image with transparent background containing only the signature. + +## Setup + +The Python PIL ([Python Image Library](http://pillow.readthedocs.io/en/latest/)) package with [Python 3](https://www.python.org/downloads/) is used in this repo. + +To install PIL via pip: +```bash +pip install pillow +``` + +## Contents + +The main script is [`signature.py`](https://github.com/RodolfoFerro/Signature/blob/master/scripts/signature.py), which contains a set of utility functions developed so far. + +### Done so far + +* Binarize your signature +* Remove background and make it transparent + +### TODO + +* Smooth image +* Image orientation +* Crop to get only signature + +## Usage + +The main script, [`signature.py`](https://github.com/RodolfoFerro/Signature/blob/master/scripts/signature.py) requires a set of parameters that are needed in the parser. + +```bash +$ python signature.py -h +usage: signature.py [-h] -i INPUT [-o OUTPUT] [-th THRESHOLD] + +optional arguments: + -h, --help show this help message and exit + -i INPUT, --input INPUT + Input image. + -o OUTPUT, --output OUTPUT + Output image. + -th THRESHOLD, --threshold THRESHOLD +``` + +An example to use this script is as follows: + +```bash +$ python signature.py -i imgs/example.jpg -o imgs/result.png -th 190 +``` + +### Results + + + +*** + +#### Reference to: + diff --git a/signature2png/imgs/example.jpg b/signature2png/imgs/example.jpg new file mode 100644 index 0000000000000000000000000000000000000000..645ea27e9f007966dbdf965705c6dd03e107c446 GIT binary patch literal 12176 zcmbW7cQo9=`|o!xRu?ro$x75DdaPcO)mJakLI@VYT0MGAgk`lLtllDO^pFr`iC%)} zEZHD>je325zkBXI=l*r?eLnN~{PUTaGp{pq=6RlZ&-L{665y65Oalf00s#Qv%>%f; z0?4WwJXJQ*HIU(Pw1432@zRmUNA#fx55G4G;pWJrp{d5BsrOWk$45#`K$r*VZR?8g z^5>D~fr?OE&jM5dAR?mwlp7+r=+I6PtVBAFDNW3 zE-5YhSo^uIzM-+Hx#fFjS9cGtx9`W;_{7i2sp(%c%PaWRwcmt4>l=If2Zu+;C#V0; z{=)?Xfc_in=KJ4Z{|6V{4HpqHF^CxaA1)w~@68LMBPO{cN=mP+54J@z+!YHWV^qQ9 z)pU?U#0_?tUU-gDF!M?*-`o2S+JBM#-+_hyf06w!u>Z|91E2x{Zzc~!2T%l@&(XsG z1?Z4eo)=^%g=FSQ*p#m91vCA^BAaVprH?x70eTX1nW%7pqYb7%`~oH7-nLW8{zA zCufP`n>#QbEP8v-7*xeHpv-;2`}OW^ZQ%Ifln@Q!9VLfQKcgxE-nU|4L)%@xORt1Z5=a~T&${RYL(HRQO#n*t_ z-vWY{*hkLC%?=Wu>hvUj@wJoaBOQ^QtDiDotS9KtF#DQyuY z3(qzlKX|K9}l|zkMP_fqZ{$KG76-+i(fy`@(=Qyi7pahC)h?Q zUrsz<<{oZym9l8m)l5_{J9|BDwl{u1rmef?_PlhVClaS^*f*rB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K18aeZdtK)kS_^ADwLd!?8SNSn_C<;&?ra4e1=kha)Y0Y6>dOxOnJkx3)$=(q-R$ zbL(F*@izPIV(+VqD6)Jnk)>kQGkMHmqi|4Z__5Jxn!9a<@S6%L>6paz1DcX zg2d}g%Nj`ZaaADBZh>4}wpsEdFE}P9iV_&J{isUfj1t18ftwPyj-T9KPMow!Kewfl zkgM#<>QW}Xx$Ced>qu&fztxUTp>JsS7q^RDh($*EOlTqkXKP}cr1jQ6HYA>{lei6n zDF%WGcg0da{Jm7{Bx02z$j6h&fYZJ#lh}Dm?Ape^4_U?>vZvi&8d}>sXO(`QanSnZ zhUJSrv)D|z#sF@op9=hRw#-$ljG(tT&h`1|tx4&2^OjvB zrE4`HZ0so&u58p0G`v+gdkf>D( z%r*2PaZPGg9_P7Xr>b3!h#lIZr~EF}BdY;nk9)@z*euCSo-gU7rmzm>tS{yPrQ))e z%ERpGg+OTw+4iXGJW88({j`6*mHN3Yh?n>7JE2r_RjTz>?~GCwbXwYh^?y@}5s{|6w2D((OP literal 0 HcmV?d00001 diff --git a/signature2png/signature.py b/signature2png/signature.py new file mode 100644 index 0000000..e6cd21a --- /dev/null +++ b/signature2png/signature.py @@ -0,0 +1,90 @@ +# =============================================================== +# Author: Rodolfo Ferro Pérez +# Email: ferro@cimat.mx +# Twitter: @FerroRodolfo +# +# Script: Process signatures to remove background. +# +# ABOUT COPYING OR USING PARTIAL INFORMATION: +# This script was originally created by Rodolfo Ferro. Any +# explicit usage of this script or its contents is granted +# according to the license provided and its conditions. +# =============================================================== + +from PIL import Image, ImageOps +import argparse + +inFile = '' +outFile = '' + + +def binarize(img, threshold=127): + """Utility function to binarize an image.""" + + for i in range(img.size[0]): + for j in range(img.size[1]): + if img.getpixel((i, j)) > threshold: + img.putpixel((i, j), 255) + else: + img.putpixel((i, j), 0) + + return img + + +def make_transparent(img): + """Utility function to make transparent background from image.""" + + img = img.convert("RGBA") + data = img.getdata() + + transparent = [] + for item in data: + if item[:3] == (255, 255, 255): + transparent.append((255, 255, 255, 0)) + else: + transparent.append(item) + + img.putdata(transparent) + return img + + +def main(inFile, outFile, threshold=190): + """Main function to process image.""" + + img = Image.open(inFile).convert('L') + img = binarize(img, threshold=threshold) + img = make_transparent(img) + img.save(outFile) + + return True + + +def parser(): + """Argument parser function.""" + + # Construct the argument parser: + ap = argparse.ArgumentParser() + + ap.add_argument("-i", "--input", + required=True, + type=str, + default="result.png", + help="Input image.") + + ap.add_argument("-o", "--output", + type=str, + default="result.png", + help="Output image.") + + ap.add_argument("-th", "--threshold", + type=int, + default=127) + + args = vars(ap.parse_args()) + + return args['input'], args['output'], args['threshold'] + + +if __name__ == "__main__": + inFile, outFile, threshold = parser() + main(inFile, outFile, threshold=threshold) From ea6d078145b17f6caef87957ebde8268558b151b Mon Sep 17 00:00:00 2001 From: Max von Forell Date: Thu, 3 Oct 2019 16:06:51 +0200 Subject: [PATCH 3/6] Add script to run a Minecraft server in the background --- Minecraft_server_in_background/README.md | 22 ++++++++++++++++++ Minecraft_server_in_background/run.py | 29 ++++++++++++++++++++++++ Minecraft_server_in_background/start.sh | 3 +++ README.md | 1 + 4 files changed, 55 insertions(+) create mode 100644 Minecraft_server_in_background/README.md create mode 100644 Minecraft_server_in_background/run.py create mode 100644 Minecraft_server_in_background/start.sh diff --git a/Minecraft_server_in_background/README.md b/Minecraft_server_in_background/README.md new file mode 100644 index 0000000..3011a56 --- /dev/null +++ b/Minecraft_server_in_background/README.md @@ -0,0 +1,22 @@ +# Running a Minecraft server in the background + +This program runs a script (which can be specified) in a subprocess with redirected output +(new output location can be specified) and periodically checks a file for a keyword (both +the name of the file to check and the keyword to check for can be specified) +and exits (stopping the subprocess via sending a command), if the contents of the file +include the keyword. + +You probably want to run this script in background, e.g. calling it via './run.py &' +or via 'nohup ./run.py &'. + +A sample invocation could look like this: + +```bash +nohup ./run.py & +``` +Now the specified script, e.g. a Minecraft server, is running in the background. + +```bash +echo stop > command.txt +``` +After a short delay, the script in the background will be stopped. diff --git a/Minecraft_server_in_background/run.py b/Minecraft_server_in_background/run.py new file mode 100644 index 0000000..988e2e1 --- /dev/null +++ b/Minecraft_server_in_background/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import subprocess +import time + +filename_script = './start.sh' # the script that will be executed +filename_script_output = './log.txt' +filename_own_input = 'command.txt' # the file this script periodically reads from +stop_command = b'stop\n' # must be a binary string +exit_keyword = 'stop' + +with open(filename_own_input, 'w') as f: + f.write('') # reset content of file and create it if needed + +fd_script_output = open(filename_script_output, 'w') # create file descriptor for script to write its stdout to +script_process = subprocess.Popen( # start new process running script + filename_script, + stdin=subprocess.PIPE, # needed for script_process.communicate() (see below) + stdout=fd_script_output # redirect output +) + +while True: + with open(filename_own_input, 'r') as f: + if exit_keyword in f.read(): # check if we should exit + script_process.communicate(input=stop_command) # stop subprocess and wait for it to terminate + break + time.sleep(1) + +fd_script_output.close() diff --git a/Minecraft_server_in_background/start.sh b/Minecraft_server_in_background/start.sh new file mode 100644 index 0000000..3b5b50e --- /dev/null +++ b/Minecraft_server_in_background/start.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +java -Xmx2048M -Xms2048M -jar server.jar -nogui diff --git a/README.md b/README.md index 89b4a09..8edcfe2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ So far, the following projects have been integrated to this repo: |[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) | |[Image To PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/images2pdf)|[msaoudallah](https://github.com/msaoudallah)| |[Instadp Web Scrapper](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/InstadpShower)|[Psychiquest](https://github.com/psychiquest)| +|[Minecraft Server in background](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Minecraft_server_in_background)|[Max von Forell](https://github.com/mvforell)| |[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()| |[Port Scanner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Port_Scanner)|[Plutoberth](https://github.com/Plutoberth)| |[Python Algebra Solver](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Algebra-Solver)|[Sengxay Xayachack](https://github.com/frankxayachack)| From f5046cde5a565bb438195ebbe8369d471052666e Mon Sep 17 00:00:00 2001 From: willian GL Date: Thu, 3 Oct 2019 22:54:18 -0300 Subject: [PATCH 4/6] Adding cli_calculator on project and also updating readme --- README.md | 9 +++++---- cli_calculator/README.md | 11 +++++++++++ cli_calculator/calc/__init__.py | 3 +++ cli_calculator/calc/args.py | 29 +++++++++++++++++++++++++++++ cli_calculator/calc/calc.py | 22 ++++++++++++++++++++++ cli_calculator/tests/test_calc.py | 28 ++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 cli_calculator/README.md create mode 100644 cli_calculator/calc/__init__.py create mode 100644 cli_calculator/calc/args.py create mode 100644 cli_calculator/calc/calc.py create mode 100644 cli_calculator/tests/test_calc.py diff --git a/README.md b/README.md index 89b4a09..626f1e9 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ So far, the following projects have been integrated to this repo: |[Gmail Mailing Script](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/mailing) |[mayank-kapur](https://github.com/kapurm17) | |[Handwrting DNN recognizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Handwriting_Recognizer) |[Chris]() | |[HTML Table to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/HTML_Table_to_List) | [Nitish Srivastava](https://github.com/nitish-iiitd)| -|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) | +|[Image circle formatter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image-Circulator) |[Berk Gureken](https://github.com/bureken) | |[Image To PDF](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/images2pdf)|[msaoudallah](https://github.com/msaoudallah)| |[Instadp Web Scrapper](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/InstadpShower)|[Psychiquest](https://github.com/psychiquest)| |[Own IP locator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Location_Of_Own_IP_Adress)|[Chris]()| @@ -53,6 +53,7 @@ So far, the following projects have been integrated to this repo: |[Youtube video downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)| |[Zabbix API](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zabbix_api)|[msg4sunny](https://github.com/msg4sunny)| |[Zip password cracker](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)| +|[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) | ## How to use : @@ -63,14 +64,14 @@ Remember to star the repo if you love the scipts~ :wink: ## Contribuition Guidelines : - Make a **separate folder** for your script. -- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol) +- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol) - :x: Script One - :heavy_check_mark: Script_One - :heavy_check_mark: Script-One - The Folder should contain the followings - - - Main Python Script, + - Main Python Script, - Supporting files for the Script (If any) - A separate `README.md` File with proper documentation. - + - Feel Free to add your script in the [project's list](https://github.com/hastagAB/Awesome-Python-Scripts#what-do-we-have) above. diff --git a/cli_calculator/README.md b/cli_calculator/README.md new file mode 100644 index 0000000..2d2955e --- /dev/null +++ b/cli_calculator/README.md @@ -0,0 +1,11 @@ +# calc_argparser +Calculadora via CLI + +# Instructions +To run CLI_Calculator execute: + +- `python args.py -h` - For help +- `python args.py --sum x y` - To sum two numbers +- `python args.py --sub x y` - To substraction two numbers +- `python args.py --mult x y` - To multiplication two numbers +- `python args.py --div x y` - To divide two numbers diff --git a/cli_calculator/calc/__init__.py b/cli_calculator/calc/__init__.py new file mode 100644 index 0000000..7383c1c --- /dev/null +++ b/cli_calculator/calc/__init__.py @@ -0,0 +1,3 @@ +from .calc import sub, mult, div, soma + +__all__ = ['sub', 'mult', 'div', 'soma'] diff --git a/cli_calculator/calc/args.py b/cli_calculator/calc/args.py new file mode 100644 index 0000000..f5c2d4f --- /dev/null +++ b/cli_calculator/calc/args.py @@ -0,0 +1,29 @@ +"""Calculadora utilizando ArgumentParser.""" + +from argparse import ArgumentParser + +from calc import soma, sub, mult, div + + +parser = ArgumentParser(description='Calculadora') + +parser.add_argument('--sum', help='Operação de soma', action='store_true') +parser.add_argument('--sub', help='Operação de subtração', action='store_true') +parser.add_argument('--mult', help='Operação de multiplicação', action='store_true') +parser.add_argument('--div', help='Operação de divisão', action='store_true') +parser.add_argument('x', type=int, help='Primeiro valor') +parser.add_argument('y', type=int, help='Segundo valor') + +args = parser.parse_args() + +if args.sum: + print(f'{soma(args.x, args.y)}') + +if args.sub: + print(f'{sub(args.x, args.y)}') + +if args.mult: + print(f'{mult(args.x, args.y)}') + +if args.div: + print(f'{div(args.x, args.y)}') diff --git a/cli_calculator/calc/calc.py b/cli_calculator/calc/calc.py new file mode 100644 index 0000000..d424dbe --- /dev/null +++ b/cli_calculator/calc/calc.py @@ -0,0 +1,22 @@ + +def soma(x :int, y: int) -> int: + """Função de soma.""" + return x + y + + +def sub(x :int, y: int) -> int: + """Função de subtração.""" + return x - y + +def mult(x :int, y: int) -> int: + """Função de multiplicação.""" + return x * y + + +def div(x :int, y: int) -> int: + """Função de divisão.""" + try: + return x / y + + except ZeroDivisionError: + return 'Divisao por zero mal sucedida!!' diff --git a/cli_calculator/tests/test_calc.py b/cli_calculator/tests/test_calc.py new file mode 100644 index 0000000..13212e4 --- /dev/null +++ b/cli_calculator/tests/test_calc.py @@ -0,0 +1,28 @@ +from unittest import TestCase + +from calc import soma, sub, mult, div + + +class testCalc(TestCase): + def test_should_return_two_values_sum(self): + esperado = 1 + 2 + self.assertEqual(esperado, soma(1,2)) + + + def test_should_return_two_values_sub(self): + esperado = 1 - 2 + self.assertEqual(esperado, sub(1,2)) + + + def test_should_return_two_values_mult(self): + esperado = 1 * 2 + self.assertEqual(esperado, mult(1,2)) + + def test_should_return_two_values_div(self): + esperado = 1 / 2 + self.assertEqual(esperado, div(1,2)) + + + def test_should_return_exceptio_on_division_by_zero(self): + esperado = 'Divisao por zero mal sucedida!!' + self.assertEqual(esperado, div(1,0)) From 7c304b1285f57fc0a47db0a98767eee69194ca6a Mon Sep 17 00:00:00 2001 From: Earl Austin Avila Zuniga Date: Fri, 4 Oct 2019 11:42:36 +0800 Subject: [PATCH 5/6] added script to README added script (Find PhoneNumber in String) to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 89b4a09..ed20051 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ So far, the following projects have been integrated to this repo: |[Youtube video downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)| |[Zabbix API](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zabbix_api)|[msg4sunny](https://github.com/msg4sunny)| |[Zip password cracker](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)| +|[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)| ## How to use : From a98e652eebd709d0900e428d7781ae4615792669 Mon Sep 17 00:00:00 2001 From: yashYRS Date: Sat, 5 Oct 2019 09:01:13 +0530 Subject: [PATCH 6/6] Added script to extract information from IMDB about any TV show --- README.md | 1 + imdb_episode_ratings/README.md | 19 ++++++ imdb_episode_ratings/scraper.py | 107 ++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 imdb_episode_ratings/README.md create mode 100644 imdb_episode_ratings/scraper.py diff --git a/README.md b/README.md index 91e10fd..cbd22ec 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ So far, the following projects have been integrated to this repo: |[Zip password cracker](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)| |[CLI Calculator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/cli_calculator)|[Willian GL](https://github.com/williangl) | |[Find PhoneNumber in String](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Find-PhoneNumber-in-String)|[Austin Zuniga](https://github.com/AustinZuniga)| +|[IMDB TV Series Info Extractor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/imdb_episode_ratings)|[Yash Raj Sarrof](https://github.com/yashYRS) | ## How to use : diff --git a/imdb_episode_ratings/README.md b/imdb_episode_ratings/README.md new file mode 100644 index 0000000..4e0154b --- /dev/null +++ b/imdb_episode_ratings/README.md @@ -0,0 +1,19 @@ +# Get information about your favorite TV shows at once +This python script will make a excel files, with information about every episode from every season of the TV show that you searched for + +## Requirement + +Python 3.6 onwards +```bash +pip3 install requests +pip3 install xlwt +pip3 install bs4 + +``` + +#Usage +Call python following with the simple algebra problem +```bash +$ python scraper.py +``` +Then simply enter the name of the show you want to search for, and then you will find a excel file in the same directory with the name of the show you searched for \ No newline at end of file diff --git a/imdb_episode_ratings/scraper.py b/imdb_episode_ratings/scraper.py new file mode 100644 index 0000000..ace4c9b --- /dev/null +++ b/imdb_episode_ratings/scraper.py @@ -0,0 +1,107 @@ +import requests +from bs4 import BeautifulSoup as BS +import xlwt +import time + + +def get_static_html ( search_url ) : + ## create the soup object for the page + try: + r_page = requests.get ( search_url ) + except: + print("Connection refused by the server..") + time.sleep(5) + soup_object = BS( r_page.content , 'html.parser' ) + #print ( soup_object.prettify() ) + return soup_object + +def get_url () : + ## convert to query url , and get raw HTML for the page + show_name = input ( " Enter show name ") + show_name = '+'.join ( show_name.split() ) + search_url = "https://www.imdb.com/find?ref_=nv_sr_fn&q="+ show_name + "&s=all" + return search_url, show_name + + +def get_new_url ( soup_object ) : + ## list of possible search results + list_queries = soup_object.find_all('td', class_ = "result_text") + + show_final = None + ## find the first TV show listing in the relevant searches + for show in list_queries : + if "(TV Series)" in show.text : + show_final = show + break + + if show_final == None : + print( " No relevant search ") + exit() + #print ( " Show found - " , show_final ) + + ## find the link to open the new page + hyperlink = show_final.find('a') + url_change = hyperlink['href'] + + show_url = "https://www.imdb.com/" + url_change + "episodes?season=" + return show_url + + +def start() : + + search_url , show_name = get_url() + soup_object = get_static_html(search_url) + show_url = get_new_url(soup_object) + result_file = xlwt.Workbook() + + season_number = 1 + + while True : + + soup_object = get_static_html( show_url + str(season_number) ) + + ## verify if extra season exists + verify_season = soup_object.find('h3' , attrs = {'id' :'episode_top'}) + curr_season = int ( verify_season.text[6:] ) + if not season_number == curr_season : + break + + print ("Season - ", season_number , " information extracted " ) + + ## excel file + result_sheet = result_file.add_sheet( verify_season.text , cell_overwrite_ok=True) + result_sheet.write( 0 , 0 , " Name " ) + result_sheet.write( 0 , 1 , " Rating " ) + result_sheet.write( 0 , 2 , " Total votes " ) + result_sheet.write( 0 , 3 , " Summary " ) + result_sheet.col(3).width = 21000 + result_sheet.col(0).width = 10000 + + episodes_season = soup_object.find_all('div' , class_ = 'info' ) + curr_episode = 1 + for episode in episodes_season : + ## get the name of the episode + name_episode = episode.find('strong') + ## get the rating of the episode + rating_episode = episode.find('span' , class_ = 'ipl-rating-star__rating' ) + ## total votes + votes_episode = episode.find('span' , class_ = 'ipl-rating-star__total-votes' ) + ## summary + summary_episode = episode.find('div' , class_ = 'item_description' ) + + ## write to the excel file + if name_episode : + result_sheet.write( curr_episode , 0 , name_episode.text ) + if rating_episode : + result_sheet.write( curr_episode , 1 , rating_episode.text ) + if votes_episode : + result_sheet.write( curr_episode , 2 , votes_episode.text[1:-1] ) + if summary_episode : + result_sheet.write( curr_episode , 3 , summary_episode.text ) + curr_episode = curr_episode + 1 + season_number = season_number + 1 + + print ( " Finished ") + result_file.save( show_name.replace('+' , '_') + '.xls') + +start() \ No newline at end of file