diff --git a/OOP/@classmethod_@staticmethod.py b/OOP/@classmethod_@staticmethod.py new file mode 100644 index 0000000..7fbf285 --- /dev/null +++ b/OOP/@classmethod_@staticmethod.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 11:44:06 2020 + +@author: saura +""" +class PlayerCharacter: + membership = True + def __init__(self, name, age): + if self.membership : + self.name = name + self.age = age + + def run(self): + print(f"run {self.name}") + + @classmethod # we can use this method without instantiating the class + def add_things(cls, n1, n2): + return cls('Jojo', n1+n2) + + @staticmethod # same as @classmethod, only thing is we don't pass the class as argument, and hence can't use its attribute + def add_things2(n1, n2): + return n1+n2 + +player1 = PlayerCharacter.add_things(4,5) +print(player1.name) +print(player1.age) +print(player1.membership) + +print(PlayerCharacter.add_things2(45, 5)) +# print(player2.membership) # gives error diff --git a/OOP/OOP.py b/OOP/OOP.py new file mode 100644 index 0000000..a196526 --- /dev/null +++ b/OOP/OOP.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 09:34:05 2020 + +@author: saura +""" +#OOP +class BigObject: + pass + +obj1 = BigObject() +obj2 = BigObject() +obj3 = BigObject() + +print(type(None)) +print(type(True)) +print(type(5)) +print(type(5.5)) +print(type('hi')) +print(type([])) +print(type(())) +print(type({})) +print(type(obj1)) \ No newline at end of file diff --git a/OOP/class.py b/OOP/class.py new file mode 100644 index 0000000..674024b --- /dev/null +++ b/OOP/class.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 10:56:03 2020 + +@author: saura +""" +class PlayerCharacter: + def __init__(self, name, age): + self.name = name # Attribute or Property + self.age = age + print("I get printed at every instance created") + def run(self): + print("run method") + +player1 = PlayerCharacter("Rohan", 22) +player2 = PlayerCharacter("Mohan", 98) +player2.attack = True # creating a new attribute for the player2 + +print(player1) # Memory location of the object +print(player1.name) # Notice that we are accessing the attributes, and hence we are not using the curly brackets at the end +print(player1.age) + +print(player2) +print(player2.name) +print(player2.age) + +print(player1.run()) # Here we are accessing the method, and hence using curly brackets + +print(player2.attack) + +''' +Note: Self refers to the object itself. So, self.name is nothing but player1.name +this way by using self, we pass the object itself to the class. +Every class method should have first argument as 'self' +and first method should be __init__ method. +''' \ No newline at end of file diff --git a/OOP/class_attribute_method.py b/OOP/class_attribute_method.py new file mode 100644 index 0000000..92c4b80 --- /dev/null +++ b/OOP/class_attribute_method.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 11:16:03 2020 + +@author: saura +""" +class PlayerCharacter: + membership = True # Class object attribute, its an attribute of PlayerCharacter. It is a static attribute + def __init__(self, name, age): + if self.membership : # or we can write: 'if PlayerCharacter.membership :' + self.name = name # these are dynamic attribute + self.age = age + + def run(self): + print(f"run {self.name}") + # print(f"run {PlayerCharacter.name}) # we cannot do this + +player1 = PlayerCharacter("Rohan", 22) +player2 = PlayerCharacter("Mohan", 98) + +print(player1.name) +print(player1.membership) # each of the class instace can assess the class object attribute +print(player1.run()) diff --git a/OOP/dunder_methods.py b/OOP/dunder_methods.py new file mode 100644 index 0000000..161e0ef --- /dev/null +++ b/OOP/dunder_methods.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 14:36:41 2020 + +@author: saura +""" +class ActionFig(): + def __init__(self, color, age): + self.color = color + self.age = age + self.my_dict = {"name": "yoyo", "has_pets": "Dog"} + + def __str__(self): + return f'{self.color}' + + def __len__(self): + return 5 + + def __call__(self): + return 'hello...??' + + def __getitem__(self, i): + return self.my_dict[i] + + def __del__(self): + return 'deleted' + +hulk = ActionFig("red", 0) + +print(hulk.__str__()) +print(hulk) +print(str(hulk)) +print(str('Printing an string')) + +print(hulk.__len__()) +print(len(hulk)) +print(len('0123456789')) + +print(hulk.__call__()) +print(hulk()) # with call method, we get this special power to call a method with curly braces + +print(hulk.__getitem__("has_pets")) + +print(hulk.__repr__()) # it is same as print(hulk), it prints the memory location of the object + +print(hulk.__del__()) +del hulk # this deletes the variable passed, but as we have modified it, it won't delete the instance now + +a = 5 +del a +# print(a) +''' +this will give us error, because we have deleted the variable a, +because we haven't modified the base class __del__ method, so its performing normal +''' diff --git a/OOP/exercise.py b/OOP/exercise.py new file mode 100644 index 0000000..6085ece --- /dev/null +++ b/OOP/exercise.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 14:14:52 2020 + +@author: saura +""" +class Pets(): + animals = [] + def __init__(self, animals): + self.animals = animals + + def walk(self): + for animal in self.animals: + print(animal.walk()) + +class Cat(): + is_lazy = True + + def __init__(self, name, age): + self.name = name + self.age = age + + def walk(self): + return f'{self.name} is just walking around' + +class Simon(Cat): + def sing(self, sounds): + return f'{sounds}' + +class Sally(Cat): + def sing(self, sounds): + return f'{sounds}' + +#1 Add nother Cat +class Suzy(Cat): + def sing(self, sounds): + return f'{sounds}' + +#2 Create a list of all of the pets (create 3 cat instances from the above) +my_cats = [Simon('Simon', 4), Sally('Sally', 21), Suzy('Suzy', 1)] + +#3 Instantiate the Pet class with all your cats +my_pets = Pets(my_cats) + +#4 Output all of the cats singing using the my_pets instance +my_pets.walk() \ No newline at end of file diff --git a/OOP/extending_list.py b/OOP/extending_list.py new file mode 100644 index 0000000..8f01e39 --- /dev/null +++ b/OOP/extending_list.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 19:21:12 2020 + +@author: saura +""" +class SuperList(list): + def __len__(self): + return 1000 + +super_list1 = SuperList() +print(super_list1) + +super_list1.append(0) +super_list1.append(100) +print(super_list1) + +print(len(super_list1)) + +print(issubclass(SuperList, list)) +print(issubclass(list, object)) diff --git a/OOP/inheritance.py b/OOP/inheritance.py new file mode 100644 index 0000000..d281782 --- /dev/null +++ b/OOP/inheritance.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 13:23:35 2020 + +@author: saura +""" +class User(): + def signed_in(self): + print("User is logged in.") + +class Wizard(User): + def __init__(self, name, power): + self.name = name + self.power = power + + def attack(self): + print(f"{self.name} is attacking with {self.power} power.") + +class Archer(User): + pass + +wizard1 = Wizard("John", 50) +archer1 = Archer() + +print(wizard1.signed_in()) +print(wizard1.attack()) + +print(archer1.signed_in()) diff --git a/OOP/isinstance.py b/OOP/isinstance.py new file mode 100644 index 0000000..a790840 --- /dev/null +++ b/OOP/isinstance.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 13:33:45 2020 + +@author: saura +""" +class User(): + def signed_in(self): + print("User is logged in.") + +class Wizard(User): + def __init__(self, name, power): + self.name = name + self.power = power + + def attack(self): + print(f"{self.name} is attacking with {self.power} power.") + +class Archer(User): + pass + +wizard1 = Wizard("John", 50) + +print(isinstance(wizard1,Wizard)) +print(isinstance(wizard1,User)) +print(isinstance(wizard1,object)) +print(isinstance(wizard1,Archer)) + +''' +By default every class is a subclass of 'object' class, hence when we type 'instance.' (object_name dot), we get all those +defualt methods suggestions from the IDE. +''' \ No newline at end of file diff --git a/OOP/mro.py b/OOP/mro.py new file mode 100644 index 0000000..7227701 --- /dev/null +++ b/OOP/mro.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 20:43:40 2020 + +@author: saura +""" +# Method Resolution Order +# it tells the order of the preferences for classes + +class A: + num = 10 + +class B(A): + pass + +class C(A): + num = 1 + +class D(B,C): + pass + +print(D.num) + +print(D.mro()) +print(D.__mro__) +# both the above are same diff --git a/OOP/mro2.py b/OOP/mro2.py new file mode 100644 index 0000000..5cac588 --- /dev/null +++ b/OOP/mro2.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 21:04:09 2020 + +@author: saura +""" +class X:pass +class Y:pass +class Z:pass +class A(X,Y):pass +class B(Y,Z):pass +class M(B,A,Z):pass + +print(M.mro()) + +# avoid using this in codes, because MRO rules are very confusing to understand. diff --git a/OOP/multiple_inheritance.py b/OOP/multiple_inheritance.py new file mode 100644 index 0000000..5bdd811 --- /dev/null +++ b/OOP/multiple_inheritance.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 20:23:27 2020 + +@author: saura +""" +class User(): + def signed_in(self): + print("User is logged in.") + +class Wizard(User): + def __init__(self, name, power): + self.name = name + self.power = power + + def attack(self): + print(f"{self.name} is attacking with {self.power} power.") + +class Archer(User): + def __init__(self, name, arrows): + self.name = name + self.arrows = arrows + + def attack(self): + print(f"{self.name} is attacking with {self.arrows} arrows.") + + def check_arrows(self): + print(f"{self.arrows} arrows left.") + +class HybridAttacker(Wizard, Archer): # notice the order, in that order only it will give preference + def __init__(self, name, power, arrows): + Wizard.__init__(self,name,power) + Archer.__init__(self,name,arrows) + +hbot = HybridAttacker("Hydro", 50, 300) +hbot.attack() + +print(hbot.name) +print(hbot.power) +print(hbot.arrows) + +hbot.check_arrows() + +hbot.signed_in() diff --git a/OOP/object_introspection.py b/OOP/object_introspection.py new file mode 100644 index 0000000..b082722 --- /dev/null +++ b/OOP/object_introspection.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 14:30:53 2020 + +@author: saura +""" +print(dir(list)) + +''' +It gives us all the methods and attributes that the item has access to. +But we get this functionality with IDEs build in, when we type item or instance name dot +for eg. +list. +and then IDE will pop a window with all the methods and attributes it has access to. +''' \ No newline at end of file diff --git a/OOP/polymorphism.py b/OOP/polymorphism.py new file mode 100644 index 0000000..73a1d75 --- /dev/null +++ b/OOP/polymorphism.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 13:44:24 2020 + +@author: saura +""" +class User(): + def signed_in(self): + print("User is logged in.") + + def attack(self): + print("Do nothing.") + +class Wizard(User): + def __init__(self, name, power): + self.name = name + self.power = power + + def attack(self): + User.attack(self) # Just a way to use parent class method. + print(f"{self.name} is attacking with {self.power} power.") + +class Archer(User): + def __init__(self, name, arrow): + self.name = name + self.arrow = arrow + + def attack(self): + print(f"{self.name} is attacking with {self.arrow} arrows.") + +wizard1 = Wizard("John", 50) +archer1 = Archer("Mohan", 85) + +wizard1.attack() +archer1.attack() +# notice that these two instances are executing the child class method and not the parent class method. + +''' +This is polymorphism. +Even though we are using the same function, it is giving different output based on the object. +''' \ No newline at end of file diff --git a/OOP/public_private.py b/OOP/public_private.py new file mode 100644 index 0000000..32118d4 --- /dev/null +++ b/OOP/public_private.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 12:23:05 2020 + +@author: saura +""" +class PlayerCharacter: + def __init__(self, name, age): + self.name = name + self.age = age + + def run(self): + print(f"run {self.name}") + +player1 = PlayerCharacter("Rohan", 22) +player2 = PlayerCharacter("Mohan", 20) + +player1.name = "!!!!" +player1.run = "BOOOO" + +print(player1.name) +print(player1.run) + +print(player2.name) +print(player2.run()) + +''' +Here the user has overwritten the class attributes and methods. +Which we would ideally don't want users to do. +However for other users, like player2, all the orginal attributes and methods functionality is intact. +Hence there is a need for Private attributes and methods, so the user cannot modify them. + +But in Python the concept of Private is not there, so we have to work around that. + +So, we can use: + class PlayerCharacter: + def __init__(self, name, age): + self._name = name + self._age = age + + player1 = PlayerCharacter("Rohan", 22) + player1.name = "!!!!" + +The user can still modify the attribute, by using 'player1._name = "!!!!"', but we are just letting him know +that '_name' is a private variable, and you should not change it. + +It's a naming convention to start a private variable with '_' (an underscore), +so other users will get to know about it. +Similarly we don't ever modify 'dunder' methods, they start and ends with two underscores (for eg. __init__) + +''' \ No newline at end of file diff --git a/OOP/super.py b/OOP/super.py new file mode 100644 index 0000000..c580e69 --- /dev/null +++ b/OOP/super.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 18 14:18:03 2020 + +@author: saura +""" +class User(): + def __init__(self, email): + self.email = email + + def signed_in(self): + print("User is logged in.") + + def attack(self): + print("Do nothing.") + +class Wizard(User): + def __init__(self, name, power, email): + self.name = name + self.power = power + super().__init__(email) # same as using the below command, it does not take 'self' parameter + # User.__init__(self, email) + + def attack(self): + print(f"{self.name} is attacking with {self.power} power.") + +wizard1 = Wizard("John", 50, 'john@gmail.com') +print(wizard1.email) + \ No newline at end of file diff --git a/Regular Expressions/email_password_regex.py b/Regular Expressions/email_password_regex.py new file mode 100644 index 0000000..538527c --- /dev/null +++ b/Regular Expressions/email_password_regex.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Aug 23 18:18:40 2020 + +@author: saura +""" +import re + +email_pattern = re.compile(r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)") +check_email = email_pattern.fullmatch('saurabh_1089@gmail.com') + +password_patter = re.compile(r"([a-zA-Z0-9@#$%]{8,}$)") +check_password = password_patter.fullmatch('12345678') + +if check_email and check_password: + print("Both email and password are correct.") +else: + print("Try again.") + +''' +password is also checking for minimum 8 chars +''' diff --git a/Regular Expressions/regular_exp.py b/Regular Expressions/regular_exp.py new file mode 100644 index 0000000..8af3722 --- /dev/null +++ b/Regular Expressions/regular_exp.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Aug 23 17:22:13 2020 + +@author: saura +""" +import re + +string = "this is a really cool string really!" + +a = re.search('really',string) +print(a) + +# the below 4 commands will give error if the searching string does not exist. +print(a.span()) +print(a.start()) +print(a.end()) +print(a.group()) + +pattern = re.compile('really') + +b = pattern.search(string) +c = pattern.findall(string) + +pattern = re.compile('this is a really cool string really!') +d = pattern.fullmatch('this is a really cool string really!') +e = pattern.fullmatch('hello this is a really cool string really!') # this should be exact match, otherwise returns none + +pattern = re.compile('really') +f = pattern.match('really cool feature') # it starts matching from the first character otherwise returns none +g = pattern.match('yo really') + +print(f"b: {b}") +print(f"c: {c}") +print(f"d: {d}") +print(f"e: {e}") +print(f"f: {f}") +print(f"g: {g}") diff --git a/Scripting/JPG/4.1 pikachu.jpg b/Scripting/JPG/4.1 pikachu.jpg new file mode 100644 index 0000000..420a7c7 Binary files /dev/null and b/Scripting/JPG/4.1 pikachu.jpg differ diff --git a/Scripting/JPG/4.3 bulbasaur.jpg b/Scripting/JPG/4.3 bulbasaur.jpg new file mode 100644 index 0000000..df7408b Binary files /dev/null and b/Scripting/JPG/4.3 bulbasaur.jpg differ diff --git a/Scripting/JPG/4.5 charmander.jpg b/Scripting/JPG/4.5 charmander.jpg new file mode 100644 index 0000000..d902b84 Binary files /dev/null and b/Scripting/JPG/4.5 charmander.jpg differ diff --git a/Scripting/JPG/4.5 squirtle.jpg b/Scripting/JPG/4.5 squirtle.jpg new file mode 100644 index 0000000..96aaa3f Binary files /dev/null and b/Scripting/JPG/4.5 squirtle.jpg differ diff --git a/Scripting/JPG/6.1 astro.jpg b/Scripting/JPG/6.1 astro.jpg new file mode 100644 index 0000000..24ce654 Binary files /dev/null and b/Scripting/JPG/6.1 astro.jpg differ diff --git a/Scripting/PDF/dummy.pdf b/Scripting/PDF/dummy.pdf new file mode 100644 index 0000000..774c2ea Binary files /dev/null and b/Scripting/PDF/dummy.pdf differ diff --git a/Scripting/PDF/merged.pdf b/Scripting/PDF/merged.pdf new file mode 100644 index 0000000..ce8ddbc Binary files /dev/null and b/Scripting/PDF/merged.pdf differ diff --git a/Scripting/PDF/rotated.pdf b/Scripting/PDF/rotated.pdf new file mode 100644 index 0000000..9e899ea Binary files /dev/null and b/Scripting/PDF/rotated.pdf differ diff --git a/Scripting/PDF/super.pdf b/Scripting/PDF/super.pdf new file mode 100644 index 0000000..fd92c28 Binary files /dev/null and b/Scripting/PDF/super.pdf differ diff --git a/Scripting/PDF/twopage.pdf b/Scripting/PDF/twopage.pdf new file mode 100644 index 0000000..dbf091d Binary files /dev/null and b/Scripting/PDF/twopage.pdf differ diff --git a/Scripting/PDF/wtr.pdf b/Scripting/PDF/wtr.pdf new file mode 100644 index 0000000..9ede331 Binary files /dev/null and b/Scripting/PDF/wtr.pdf differ diff --git a/Scripting/PNG/4.1 pikachu.png b/Scripting/PNG/4.1 pikachu.png new file mode 100644 index 0000000..56d791c Binary files /dev/null and b/Scripting/PNG/4.1 pikachu.png differ diff --git a/Scripting/PNG/4.3 bulbasaur.png b/Scripting/PNG/4.3 bulbasaur.png new file mode 100644 index 0000000..31ba02a Binary files /dev/null and b/Scripting/PNG/4.3 bulbasaur.png differ diff --git a/Scripting/PNG/4.5 charmander.png b/Scripting/PNG/4.5 charmander.png new file mode 100644 index 0000000..4dde97e Binary files /dev/null and b/Scripting/PNG/4.5 charmander.png differ diff --git a/Scripting/PNG/4.5 squirtle.png b/Scripting/PNG/4.5 squirtle.png new file mode 100644 index 0000000..4f22e93 Binary files /dev/null and b/Scripting/PNG/4.5 squirtle.png differ diff --git a/Scripting/PNG/6.1 astro.png b/Scripting/PNG/6.1 astro.png new file mode 100644 index 0000000..ea0591b Binary files /dev/null and b/Scripting/PNG/6.1 astro.png differ diff --git a/Scripting/Pokedex/blur.png b/Scripting/Pokedex/blur.png new file mode 100644 index 0000000..9c7dcc3 Binary files /dev/null and b/Scripting/Pokedex/blur.png differ diff --git a/Scripting/Pokedex/cropped_img.png b/Scripting/Pokedex/cropped_img.png new file mode 100644 index 0000000..0712f97 Binary files /dev/null and b/Scripting/Pokedex/cropped_img.png differ diff --git a/Scripting/Pokedex/grey.png b/Scripting/Pokedex/grey.png new file mode 100644 index 0000000..8a153a4 Binary files /dev/null and b/Scripting/Pokedex/grey.png differ diff --git a/Scripting/Pokedex/pikachu.jpg b/Scripting/Pokedex/pikachu.jpg new file mode 100644 index 0000000..420a7c7 Binary files /dev/null and b/Scripting/Pokedex/pikachu.jpg differ diff --git a/Scripting/Pokedex/resized.png b/Scripting/Pokedex/resized.png new file mode 100644 index 0000000..171de4d Binary files /dev/null and b/Scripting/Pokedex/resized.png differ diff --git a/Scripting/Pokedex/rotated.png b/Scripting/Pokedex/rotated.png new file mode 100644 index 0000000..c77b70c Binary files /dev/null and b/Scripting/Pokedex/rotated.png differ diff --git a/Scripting/Pokedex/sharpen.png b/Scripting/Pokedex/sharpen.png new file mode 100644 index 0000000..f7c47cf Binary files /dev/null and b/Scripting/Pokedex/sharpen.png differ diff --git a/Scripting/Pokedex/smooth.png b/Scripting/Pokedex/smooth.png new file mode 100644 index 0000000..91d2673 Binary files /dev/null and b/Scripting/Pokedex/smooth.png differ diff --git a/Scripting/Pokedex/thumbnailed.png b/Scripting/Pokedex/thumbnailed.png new file mode 100644 index 0000000..5c0e22d Binary files /dev/null and b/Scripting/Pokedex/thumbnailed.png differ diff --git a/Scripting/Watermark/super.pdf b/Scripting/Watermark/super.pdf new file mode 100644 index 0000000..fd92c28 Binary files /dev/null and b/Scripting/Watermark/super.pdf differ diff --git a/Scripting/Watermark/watermarked_output.pdf b/Scripting/Watermark/watermarked_output.pdf new file mode 100644 index 0000000..632f5b8 Binary files /dev/null and b/Scripting/Watermark/watermarked_output.pdf differ diff --git a/Scripting/Watermark/wtr.pdf b/Scripting/Watermark/wtr.pdf new file mode 100644 index 0000000..9ede331 Binary files /dev/null and b/Scripting/Watermark/wtr.pdf differ diff --git a/Scripting/checkmypassword.py b/Scripting/checkmypassword.py new file mode 100644 index 0000000..b58f74f --- /dev/null +++ b/Scripting/checkmypassword.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 13:06:04 2020 + +@author: saura +""" +import requests +import hashlib +import sys + +def request_api_data(query_char): + url = 'https://api.pwnedpasswords.com/range/' + query_char + res = requests.get(url) + if res.status_code != 200: # 200 means all good! + raise RuntimeError(f'Error fetching: {res.status_code}, check the api and try again') + return res + +def get_password_leaks_count(hashes, hash_to_check): + hashes = (line.split(':') for line in hashes.text.splitlines()) + for h, count in hashes: + if h == hash_to_check: + return count + return 0 + +def pwned_api_check(password): + sha1password = hashlib.sha1(password.encode('utf-8')).hexdigest().upper() + first5_char, tail = sha1password[:5], sha1password[5:] + response = request_api_data(first5_char) + return get_password_leaks_count(response, tail) + +def main(args): + for password in args: + count = pwned_api_check(password) + if count: + print(f'{password} was found {count} times... you should probably change your password!') + else: + print(f'{password} was NOT found. Carry on!') + return 'done!' + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) + #sys.exit() make sure the program ends to the command line at last. + +''' +this website takes the first 5 digit of the 'SHA 1 hash' +so we actually generate a SHA 1 hash of our password and then just pass the first five digits of the hash +so we are keeping safe our hash, so that no one can even backtrace the password using our hash. +and this website list all the hash starting with the 5 digits we have passed, and we can then manually check whether our +password has been hacked or not +''' + \ No newline at end of file diff --git a/Scripting/email_sender.py b/Scripting/email_sender.py new file mode 100644 index 0000000..999408e --- /dev/null +++ b/Scripting/email_sender.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 12:48:50 2020 + +@author: saura +""" +import smtplib +from email.message import EmailMessage +from string import Template +from pathlib import Path # or os.path + +html = Template(Path('index.html').read_text()) + +email = EmailMessage() +email['from'] = 'Universe' +email['to'] = 'saurabhkragarwal@gmail.com' +email['subject'] = 'You are cooooool' +email.set_content(html.substitute({'name': 'Saurabh'}), 'html') + +with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp: + smtp.ehlo() + smtp.starttls() + smtp.login('saurabhagarwal1089@gmail.com', 'saurabh90()') + smtp.send_message(email) + print('all good boss!') diff --git a/Scripting/image.py b/Scripting/image.py new file mode 100644 index 0000000..8840036 --- /dev/null +++ b/Scripting/image.py @@ -0,0 +1,34 @@ +from PIL import Image, ImageFilter + +img = Image.open('./Pokedex/pikachu.jpg') +print(img) +print(img.format) +print(img.size) +print(img.mode) + +filtered_img = img.filter(ImageFilter.BLUR) +filtered_img.save("./Pokedex/blur.png", "png") + +filtered_img = img.filter(ImageFilter.SMOOTH) +filtered_img.save("./Pokedex/smooth.png", "png") + +filtered_img = img.filter(ImageFilter.SHARPEN) +filtered_img.save("./Pokedex/sharpen.png", "png") + +filtered_img = img.convert('L') # it converts the image to grey scale, that is Black and White. Similarly RGB = Red Green Blue +filtered_img.save("./Pokedex/grey.png", "png") + +# filtered_img.show() # this opens the image in the default player + +rotated_img = img.rotate(45) +rotated_img.save("./Pokedex/rotated.png", "png") + +resized_img = img.resize((100,50)) # but this can ruin the aspect ratio hence we use thumbnail method +resized_img.save("./Pokedex/resized.png", "png") + +box = (100,100,400,400) +cropped_img = img.crop(box) +cropped_img.save("./Pokedex/cropped_img.png", "png") + +img.thumbnail((100,50)) # it will keep max. 50*50 aspect ratio, it can be like 30*50, but it won't exceed 50 pixels +img.save("./Pokedex/thumbnailed.png", "png") diff --git a/Scripting/index.html b/Scripting/index.html new file mode 100644 index 0000000..971812f --- /dev/null +++ b/Scripting/index.html @@ -0,0 +1,8 @@ + + +
+ + + Hello $name, You are awesome, and you know it! + + diff --git a/Scripting/jpg_to_png.py b/Scripting/jpg_to_png.py new file mode 100644 index 0000000..65ad3a2 --- /dev/null +++ b/Scripting/jpg_to_png.py @@ -0,0 +1,15 @@ +from PIL import Image, ImageFilter +import sys +import os + +img_path = sys.argv[1] +new_path = sys.argv[2] + +if not os.path.exists(new_path): + os.makedirs(new_path) + +for file in os.listdir(img_path): + img = Image.open(f'{img_path}{file}') + # new_file = file.replace(".jpg", ".png") # we can do this or the below command + new_file = os.path.splitext(file)[0] # this keeps the file name without the extension + img.save(f"{new_path}/{new_file}.png", "png") diff --git a/Scripting/pdf.py b/Scripting/pdf.py new file mode 100644 index 0000000..2b6887c --- /dev/null +++ b/Scripting/pdf.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 10:08:18 2020 + +@author: saura +""" +import PyPDF2 + +with open('./PDF/dummy.pdf', 'rb') as file: +# 'rb' is read binary, for pdf we append 'b' to it. +# so it converts the file to binary and PyPDF2 works with binary files. + reader = PyPDF2.PdfFileReader(file) + print(file) + print(reader) + print(reader.numPages) + print(reader.getPage(0)) + + page = reader.getPage(0) + page.rotateClockwise(90) + writer = PyPDF2.PdfFileWriter() + writer.addPage(page) + + with open('./PDF/rotated.pdf', 'wb') as new_file: + writer.write(new_file) + diff --git a/Scripting/pdf_merger.py b/Scripting/pdf_merger.py new file mode 100644 index 0000000..6dfd1be --- /dev/null +++ b/Scripting/pdf_merger.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 11:42:11 2020 + +@author: saura +""" +import PyPDF2 +import sys + +inputs = sys.argv[1:] # this will stores all the arguments passes except the first one, and store them in a list + +def pdf_merger(pdf_list): + merger = PyPDF2.PdfFileMerger() + for pdf in pdf_list: + merger.append(pdf) + merger.write('./PDF/merged.pdf') + +pdf_merger(inputs) diff --git a/Scripting/sms.py b/Scripting/sms.py new file mode 100644 index 0000000..82f562a --- /dev/null +++ b/Scripting/sms.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Aug 26 10:01:55 2020 + +@author: saura +""" +from twilio.rest import Client + +account_sid = 'AC35a43368114f115baac776029167317c' +auth_token = '8cfe654e7fa576d7961f8698f0b015fd' +client = Client(account_sid, auth_token) + +message = client.messages.create( + from_='+19284823038', + body='Hello Saurabh, this is your bot JARVIS! Good Morning!', + to='+919652723113' + ) + +print(message.sid) diff --git a/Scripting/twitterbot.py b/Scripting/twitterbot.py new file mode 100644 index 0000000..00c8de7 --- /dev/null +++ b/Scripting/twitterbot.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 14:38:12 2020 + +@author: saura +""" +import tweepy +import time + +consumer_key = 'UhGZOyvUbcV2AdP6qKO0JVyO5' +consumer_secret = '4rBfUDC5GI5vfWZ7wrRGWC6z8L2IRnUHVRy552kuucr22ihucr' +access_token = '184273645-bdNU0KIie6lF5dt7befq1E0O22xCB8y2w4HfMn8Z' +access_token_secret = 'LKmvs4A7c2auo4RlVLP5ArNcij1wCIhgSQ6nOeguuWq0f' + +auth = tweepy.OAuthHandler(consumer_key, consumer_secret) +auth.set_access_token(access_token, access_token_secret) +api = tweepy.API(auth) + +user = api.me() +# print(user) # it gives all the details, like name, scree_name, location, and various other info. +print (user.name) #prints your name. +print (user.screen_name) +print (user.followers_count) + +search = "bitcoin" +numberOfTweets = 2 + +def limit_handle(cursor): + while True: + try: + yield cursor.next() + + except tweepy.RateLimitError: + print("Sleeping now....") + time.sleep(10) # sleeps for 10 secs + + +# for follower in limit_handle(tweepy.Cursor(api.followers).items()): +# print(follower.name) +# if follower.name == 'Usernamehere': +# print(follower.name) +# follower.follow() + + +for tweet in tweepy.Cursor(api.search, search).items(numberOfTweets): + try: + tweet.favorite() + tweet.retweet() + except tweepy.TweepError as e: + print(e.reason) + except StopIteration: + break diff --git a/Scripting/watermark.py b/Scripting/watermark.py new file mode 100644 index 0000000..248ccd9 --- /dev/null +++ b/Scripting/watermark.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Aug 25 11:53:26 2020 + +@author: saura +""" +import PyPDF2 + +template = PyPDF2.PdfFileReader(open('./Watermark/super.pdf', 'rb')) +watermark = PyPDF2.PdfFileReader(open('./Watermark/wtr.pdf', 'rb')) +output = PyPDF2.PdfFileWriter() + +for i in range(template.getNumPages()): + page = template.getPage(i) + page.mergePage(watermark.getPage(0)) + output.addPage(page) + +with open('./Watermark/watermarked_output.pdf', 'wb') as file: + output.write(file) + diff --git a/Scripting/whatsapp_sms.py b/Scripting/whatsapp_sms.py new file mode 100644 index 0000000..e96480c --- /dev/null +++ b/Scripting/whatsapp_sms.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Aug 26 11:20:38 2020 + +@author: saura +""" +from twilio.rest import Client + +account_sid = 'ACd14286b3a8d093f71f4ec72eb9143e1f' +auth_token = 'ad3a486ed06500c654d82028e56d34df' + +client = Client(account_sid, auth_token) + +message = client.messages.create( + # media_url=['https://images.unsplash.com/photo-1545093149-618ce3bcf49d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=668&q=80'], + from_='whatsapp:+14155238886', + body="Hello Saurabh. This is your bot: JARVIS, reporting on duty!", + to='whatsapp:+919652723113' + ) + +print(message.sid) diff --git a/Testing/__pycache__/guess_game.cpython-37.pyc b/Testing/__pycache__/guess_game.cpython-37.pyc new file mode 100644 index 0000000..d92e982 Binary files /dev/null and b/Testing/__pycache__/guess_game.cpython-37.pyc differ diff --git a/Testing/__pycache__/main.cpython-37.pyc b/Testing/__pycache__/main.cpython-37.pyc new file mode 100644 index 0000000..8a0d211 Binary files /dev/null and b/Testing/__pycache__/main.cpython-37.pyc differ diff --git a/Testing/__pycache__/script.cpython-37.pyc b/Testing/__pycache__/script.cpython-37.pyc new file mode 100644 index 0000000..14313d2 Binary files /dev/null and b/Testing/__pycache__/script.cpython-37.pyc differ diff --git a/Testing/guess_game.py b/Testing/guess_game.py new file mode 100644 index 0000000..d89ff00 --- /dev/null +++ b/Testing/guess_game.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 24 13:44:51 2020 + +@author: saura +""" +import random + +def run_guess(guess, answer): + if 0 < guess < 11: + if guess == answer: + print('you are a genius!') + return True + else: + print('hey bozo, I said 1~10') + return False + +if __name__ == '__main__': # so that the game don't start while testing. + answer = random.randint(1, 10) + while True: + try: + guess = int(input('guess a number 1~10: ')) + if (run_guess(guess, answer)): + break + except ValueError: + print('please enter a number') + continue + +''' +we test a function at a time. +that is why it is called unit testing. +hence we try to make pure functions and test them. +''' \ No newline at end of file diff --git a/Testing/script.py b/Testing/script.py new file mode 100644 index 0000000..1b20715 --- /dev/null +++ b/Testing/script.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 24 10:09:27 2020 + +@author: saura +""" +def add(num): + try: + return int(num) + 5 + except ValueError as err: + return err diff --git a/Testing/test.py b/Testing/test.py new file mode 100644 index 0000000..0499af0 --- /dev/null +++ b/Testing/test.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 24 09:44:29 2020 + +@author: saura +""" +import unittest +import script + +class TestMain(unittest.TestCase): # inheriting TestCase class + + def setUp(self): # this method will run before starting all the other test methods + print("Starting a method/test: ") + + def test_add(self): + '''This is the info for this particular test''' + test_param = 10 + result = script.add(test_param) + self.assertEqual(result,15) + + def test_add2(self): + test_param = 'random string' + result = script.add(test_param) + self.assertTrue(isinstance(result,ValueError)) + + def tearDown(self): # this method will run after every test method. Generally used to reset/cleaning up data variables. + print("Cleaning up....") + + +class A: + print("\nClass A") + +if __name__ == '__main__': + unittest.main() # this will run the entire classes present in the file + + +class B: + print("Class B") diff --git a/Testing/test2.py b/Testing/test2.py new file mode 100644 index 0000000..bf20b50 --- /dev/null +++ b/Testing/test2.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 24 13:23:16 2020 + +@author: saura +""" +import unittest +import script + +class TestMain(unittest.TestCase): # inheriting TestCase class + def test_add(self): + test_param = 10 + result = script.add(test_param) + self.assertEqual(result,15) + + def test_add2(self): + test_param = 'random string' + result = script.add(test_param) + self.assertTrue(isinstance(result,ValueError)) + +if __name__ == '__main__': + unittest.main() diff --git a/Testing/test_guess_game.py b/Testing/test_guess_game.py new file mode 100644 index 0000000..31caeb0 --- /dev/null +++ b/Testing/test_guess_game.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Aug 24 13:45:14 2020 + +@author: saura +""" +import unittest +import guess_game + +class testGame(unittest.TestCase): + def test_game(self): + result = guess_game.run_guess(5,5) + self.assertTrue(result) + + def test_game2(self): + result = guess_game.run_guess(0,5) + self.assertFalse(result) + + def test_game3(self): + result = guess_game.run_guess(15,4) + self.assertFalse(result) + +if __name__ == '__main__': + unittest.main() + \ No newline at end of file diff --git a/Web Scraping/scrape.py b/Web Scraping/scrape.py new file mode 100644 index 0000000..cb2f971 --- /dev/null +++ b/Web Scraping/scrape.py @@ -0,0 +1,36 @@ +import requests +from bs4 import BeautifulSoup +import pprint + +res = requests.get('https://news.ycombinator.com/news') +res2 = requests.get('https://news.ycombinator.com/news?p=2') +soup = BeautifulSoup(res.text, 'html.parser') +soup2 = BeautifulSoup(res2.text, 'html.parser') + +links = soup.select('.storylink') +subtext = soup.select('.subtext') +links2 = soup2.select('.storylink') +subtext2 = soup2.select('.subtext') + +print(links) + + +mega_links = links + links2 +mega_subtext = subtext + subtext2 + +def sort_stories_by_votes(hnlist): + return sorted(hnlist, key= lambda k:k['votes'], reverse=True) + +def create_custom_hn(links, subtext): + hn = [] + for idx, item in enumerate(links): + title = item.getText() + href = item.get('href', None) + vote = subtext[idx].select('.score') + if len(vote): + points = int(vote[0].getText().replace(' points', '')) + if points > 99: + hn.append({'title': title, 'link': href, 'votes': points}) + return sort_stories_by_votes(hn) + +# pprint.pprint(create_custom_hn(mega_links, mega_subtext)) diff --git a/Web Scraping/scraping.py b/Web Scraping/scraping.py new file mode 100644 index 0000000..de2bb9b --- /dev/null +++ b/Web Scraping/scraping.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Aug 26 11:43:42 2020 + +@author: saura +""" +import requests +from bs4 import BeautifulSoup +import pprint # pretty print - used to print with appropriate spacing, for readability + +url = 'https://news.ycombinator.com/' +res = requests.get(url) + +# print(res) # Response 200 menas everything is good +# print(res.text) +# this will have the entire html data in it. Exactly the same thing which we get when we click 'View Page Source' + +soup = BeautifulSoup(res.text, 'html.parser') + +# print(soup) +# this will also have the exact same thing as res.text, but it will keep in html format, and not in string format, +# and it will be easier to manupulate it + +# print(soup.body) +# print(soup.body.contents) # result comes in a 'list' in this case. But not with the previous cases. + +# print(soup.find_all('div')) +# print(soup.find_all('a')) # find all the 'a' tags - all the links +# print(soup.title) +# print(soup.a) # it finds the first a tag +# print(soup.find('a')) # it finds the first a tag + +# print(soup.find(id="score_24273602")) +# print(soup.select("#score_24273602")) # outputs in a list +# select grabs the data using a CSS selector, where '.' means 'class', '#' means 'id', etc. + +# print(soup.select('a')[0]) +# grabs all the 'a' tags, and print only the first one, as this is a list, and we want the 0th item + +# print(soup.select(".score")[0])# grabs all the class="score" tags + +link = soup.select(".storylink") +# Africa declared free of wild polio + +subtext = soup.select(".subtext") +# 1061 points + +li = [] + +for i in range(len(link)): + news_link = link[i].get("href", None) # if the link is not there, the value will be taken as None + news_title = link[i].getText() + votes = subtext[i].select(".score") + if len(votes): + score = votes[0].getText().split(' ')[0] + else: + score = 0 + + if int(score) > 100: + li.append((news_title, news_link, int(score))) + +li.sort(key = lambda x:x[2], reverse=True) +# li = sorted(li, key =lambda x:x[2], reverse=True) # same as that of above + +pprint.pprint(li)