Skip to content

Commit d52e2e4

Browse files
authored
Merge branch 'main' into mypythonscript
2 parents ba0229d + 2a80986 commit d52e2e4

File tree

12 files changed

+3088
-79
lines changed

12 files changed

+3088
-79
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#a script that converts images to pdf
2+
3+
from reportlab.platypus import Image, SimpleDocTemplate
4+
5+
6+
def images_to_pdf(
7+
list_of_images: list, pdf_file_name: str, width=None, height=None, hAlign="CENTER"
8+
) -> bool:
9+
"""
10+
Function convert the image into Pdf
11+
"""
12+
pdf = SimpleDocTemplate(pdf_file_name)
13+
images = []
14+
for i in list_of_images:
15+
try:
16+
re = Image(i, width=width, height=height, hAlign=hAlign)
17+
except:
18+
pass
19+
images.append(re)
20+
pdf.build(images)
21+
22+
return True
23+
24+
25+
if __name__ == "__main__":
26+
# You Can use any source of image
27+
# Here I use posts of Instagram with hashtag 'tamil'
28+
from instagramy import InstagramHashTag
29+
30+
tag = InstagramHashTag("tamil")
31+
print(images_to_pdf(tag.posts_display_urls, "tamil.pdf", width=250, height=250))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
This script can automatically perform the google search process and open the website in default web browser.
3+
"""
4+
5+
from googlesearch import search
6+
from webbrowser import open
7+
8+
9+
def google_search(query, no_of_results):
10+
11+
result = search(query, num=no_of_results, pause=2, stop=no_of_results)
12+
13+
return result
14+
15+
16+
if __name__ == "__main__":
17+
18+
query = input("Enter the Query: ")
19+
no_of_results = int(input("Enter number of tabs open in browser: "))
20+
for i in google_search(query, no_of_results):
21+
open(i)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import csv
2+
import json
3+
4+
5+
def csv_to_json(input_csv: str, output_json: str) -> bool:
6+
"""
7+
Funtion to Convert csv to json file
8+
Funtion might need some changes according to your file organization and type
9+
"""
10+
11+
with open(input_csv, "r") as file_obj:
12+
reader = list(csv.DictReader(file_obj))
13+
json_obj = json.dumps(reader)
14+
15+
with open(output_json, "w") as file_obj:
16+
file_obj.writelines(json_obj)
17+
18+
return True
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# the calculator
2+
from tkinter import Tk, Button, Label, Grid, Entry, END
3+
4+
root = Tk()
5+
root.title("CALCULATOR")
6+
e = Entry(
7+
root,
8+
width=35,
9+
borderwidth=10,
10+
)
11+
e.grid(row=0, column=0, columnspan=4, padx=8, pady=8)
12+
13+
14+
def joker(number):
15+
now = e.get()
16+
e.delete(0, END)
17+
e.insert(0, str(now) + str(number))
18+
19+
20+
def addd():
21+
n1 = e.get()
22+
global num1
23+
global cal
24+
cal = "add"
25+
num1 = float(n1)
26+
e.delete(0, END)
27+
28+
29+
def sub():
30+
n1 = e.get()
31+
global num1
32+
global cal
33+
cal = "sub"
34+
num1 = float(n1)
35+
e.delete(0, END)
36+
37+
38+
def mul():
39+
n1 = e.get()
40+
global num1
41+
global cal
42+
cal = "mul"
43+
num1 = float(n1)
44+
e.delete(0, END)
45+
46+
47+
def div():
48+
n1 = e.get()
49+
global num1
50+
global cal
51+
cal = "div"
52+
num1 = float(n1)
53+
e.delete(0, END)
54+
55+
56+
def equ():
57+
if cal == "add":
58+
n2 = e.get()
59+
e.delete(0, END)
60+
e.insert(0, num1 + float(n2))
61+
elif cal == "sub":
62+
n2 = e.get()
63+
e.delete(0, END)
64+
e.insert(0, num1 - float(n2))
65+
elif cal == "mul":
66+
n2 = e.get()
67+
e.delete(0, END)
68+
e.insert(0, num1 * float(n2))
69+
elif cal == "div":
70+
n2 = e.get()
71+
e.delete(0, END)
72+
e.insert(0, num1 / float(n2))
73+
else:
74+
pass
75+
76+
77+
def clr():
78+
e.delete(0, END)
79+
80+
81+
# bottons
82+
btn1 = Button(root, text="1", padx=20, pady=5, command=lambda: joker("1"))
83+
btn2 = Button(root, text="2", padx=20, pady=5, command=lambda: joker("2"))
84+
btn3 = Button(root, text="3", padx=20, pady=5, command=lambda: joker("3"))
85+
btn4 = Button(root, text="4", padx=20, pady=5, command=lambda: joker("4"))
86+
btn5 = Button(root, text="5", padx=20, pady=5, command=lambda: joker("5"))
87+
btn6 = Button(root, text="6", padx=20, pady=5, command=lambda: joker("6"))
88+
btn7 = Button(root, text="7", padx=20, pady=5, command=lambda: joker("7"))
89+
btn8 = Button(root, text="8", padx=20, pady=5, command=lambda: joker("8"))
90+
btn9 = Button(root, text="9", padx=20, pady=5, command=lambda: joker("9"))
91+
btn0 = Button(root, text="0", padx=20, pady=5, command=lambda: joker("0"))
92+
btnadd = Button(root, text="+", padx=20, pady=5, command=addd)
93+
btnsub = Button(root, text="-", padx=20, pady=5, command=sub)
94+
btnmul = Button(root, text="*", padx=20, pady=5, command=mul)
95+
btndiv = Button(root, text="/", padx=20, pady=5, command=div)
96+
btnequ = Button(root, text="=", padx=20, pady=5, command=equ)
97+
btndot = Button(root, text=".", padx=20, pady=5, command=lambda: joker("."))
98+
btnclr = Button(root, text="clear", padx=20, pady=5, command=clr)
99+
100+
101+
btn1.grid(row=3, column=0)
102+
btn2.grid(row=3, column=1)
103+
btn3.grid(row=3, column=2)
104+
btn4.grid(row=2, column=0)
105+
btn5.grid(row=2, column=1)
106+
btn6.grid(row=2, column=2)
107+
btn7.grid(row=1, column=0)
108+
btn8.grid(row=1, column=1)
109+
btn9.grid(row=1, column=2)
110+
btn0.grid(row=4, column=1)
111+
btnadd.grid(row=1, column=3)
112+
btnsub.grid(row=2, column=3)
113+
btnmul.grid(row=3, column=3)
114+
btndiv.grid(row=4, column=3)
115+
btnequ.grid(row=4, column=0)
116+
btndot.grid(row=4, column=2)
117+
btnclr.grid(row=5, column=1)
118+
119+
root.mainloop()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# importing necessary libraries
2+
import img2pdf
3+
from PIL import Image
4+
import os
5+
6+
# storing image path
7+
img_path = "C:/Users/vedan/OneDrive/Desktop/image.png"
8+
9+
# storing pdf path
10+
pdf_path = "C:/Users/vedan/OneDrive/Desktop/image.pdf"
11+
12+
# opening image
13+
image = Image.open(img_path)
14+
15+
# converting into chunks using img2pdf
16+
pdf_bytes = img2pdf.convert(image.filename)
17+
18+
# opening or creating pdf file
19+
file = open(pdf_path, "wb")
20+
21+
# writing pdf files with chunks
22+
file.write(pdf_bytes)
23+
24+
# closing image file
25+
image.close()
26+
27+
# closing pdf file
28+
file.close()
29+
30+
# output
31+
print("Successfully made pdf file")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 🖼️ Image to PDF
2+
3+
## Description
4+
5+
img2pdf is an open source Python package to convert images to pdf format. It includes another module Pillow which can also be used to enhance image (Brightness, contrast and other things)
6+
7+
---
8+
9+
## Installation
10+
11+
You will need `img2pdf` package installed, you can install it by running the following command
12+
13+
```bash
14+
pip install img2pdf
15+
```
16+
17+
---
18+
19+
## Steps To Execution
20+
21+
- Fork this repo and navigate to `IMAGES & PHOTO SCRIPTS` folder
22+
- (optional) Add images to same directory with this img2pdf.py.
23+
- Modify the names in `img2pdf.py`
24+
- Run this img2pdf.py `$ python img2pdf.py`
25+
- The output directory will now include a brand-new PDF file.
26+
27+
---
28+
29+
## Output
30+
31+
```bash
32+
Image contains an alpha channel. Computing a separate soft mask (/SMask) image to store transparency in PDF.
33+
Successfully made pdf file
34+
```
35+
36+
---
37+
38+
---

0 commit comments

Comments
 (0)