Skip to content

Instantly share code, notes, and snippets.

View Kimjunkuk's full-sized avatar
👨‍💻
Fou

KIM JUNKUK Kimjunkuk

👨‍💻
Fou
View GitHub Profile
@Kimjunkuk
Kimjunkuk / report_email.py
Created January 4, 2022 02:58
Generate a PDF report and send it through email - Send report through email
#!/usr/bin/env python3
import email
import mimetypes
import smtplib
import os
def generate_email(sender, recipient, subject, body, attachment_path):
message = email.message.EmailMessage()
message["From"] = sender
message["To"] = recipient
@Kimjunkuk
Kimjunkuk / report_email.py
Created January 4, 2022 02:57
Generate a PDF report and send it through email - Send report through email
#report_email.py
#!/usr/bin/env python3
import datetime
import os
from run import catalog_data
from reports import generate_report
from emails import generate_email, send_email
def pdf_body(input_for, desc_dir):
@Kimjunkuk
Kimjunkuk / reports.py
Created January 4, 2022 02:56
Generate a PDF report and send it through email
# reports.py
#!/usr/bin/env python3
from reportlab.platypus import Paragraph, Spacer, Image, SimpleDocTemplate
from reportlab.lib.styles import getSampleStyleSheet
def generate_report(file, title, add_info):
styles=getSampleStyleSheet()
report=SimpleDocTemplate(file)
report_title=Paragraph(title, styles['h1'])
@Kimjunkuk
Kimjunkuk / health_check.py
Created January 4, 2022 02:53
Health check
#!/usr/bin/env python3
import socket
import shutil
import psutil
import emails
def check_localhost():
localhost=socket.gethostbyname('localhost')
return localhost=="127.0.0.1"
@Kimjunkuk
Kimjunkuk / run.py
Created January 4, 2022 02:00
Uploading the descriptions
#!/usr/bin/env python3
import os, requests, json
def catalog_data(url, description_dir):
fruit={}
for item in os.listdir(description_dir): # 문제
fruit.clear()
filename=os.path.join(description_dir,item)
with open(filename) as f:
@Kimjunkuk
Kimjunkuk / example_upload.py
Created January 4, 2022 01:39
Uploading images to web server
#!/usr/bin/env python3
import requests, os
# The URL to upload the images
url="http://localhost/upload/"
# To get the username from environment variable
USER = os.getenv('USER')
# The directory which contains all the images.
image_directory='/home/{}/supplier-data/images/'.format(USER)
#Listing all the files in images directory
files=os.listdir(image_directory)
@Kimjunkuk
Kimjunkuk / changeImage.py
Last active January 5, 2023 10:56
Working with supplier images
#!/usr/bin/env python3
import os, sys
from PIL import Image
user = os.getenv('USER')
image_directory = '/home/{}/supplier-data/images/'.format(user)
for image_name in os.listdir(image_directory):
if not image_name.startswith('.') and 'tiff' in image_name:
image_path = image_directory + image_name
@Kimjunkuk
Kimjunkuk / answer.py
Last active January 5, 2023 10:56
Automatically Generate a PDF and send it by Email
#!/usr/bin/env python3
import json
import locale
import sys
from reports import generate as report
from emails import generate as email_generate
from emails import send as email_send
@Kimjunkuk
Kimjunkuk / answer.py
Created January 3, 2022 02:20
5. Question 5 We have two pieces of furniture: a brown wood table and a red leather couch. Fill in the blanks following the creation of each Furniture class instance, so that the describe_furniture function can format a sentence that describes these pieces as follows: "This piece of furniture is made of {color} {material}"
class Furniture:
color = ""
material = ""
table = Furniture()
table.color="brown"
table.material="wood"
couch = Furniture()
couch.color="red"
@Kimjunkuk
Kimjunkuk / answer.py
Created January 3, 2022 02:19
3. Question 3 The City class has the following attributes: name, country (where the city is located), elevation (measured in meters), and population (approximate, according to recent statistics). Fill in the blanks of the max_elevation_city function to return the name of the city and its country (separated by a comma), when comparing the 3 defin…
# define a basic city class
class City:
name = ""
country = ""
elevation = 0
population = 0
# create a new instance of the City class and
# define each attribute
city1 = City()