Created
February 18, 2018 00:10
-
-
Save initrunlevel0/fcb04421024fa92a4a296565d81db980 to your computer and use it in GitHub Desktop.
Buku Angkatan Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pic Downloader | |
import urlparse, requests, shutil, os | |
def pic_downloader(gdrive_link, output): | |
parsed = urlparse.urlparse(gdrive_link) | |
id = urlparse.parse_qs(parsed.query)["id"][0] | |
new_gdrive_link = "https://docs.google.com/uc?export=download&id=" + str(id) | |
path = "img/" + output | |
if not os.path.isfile(path): | |
print "Downloading for " + output | |
response = requests.get(new_gdrive_link, stream=True) | |
with open(path, 'wb') as out_file: | |
shutil.copyfileobj(response.raw, out_file) | |
del response | |
# Database | |
from pandas import read_csv | |
import numpy as np | |
db = read_csv("master.csv", dtype={"Nomor Hape": str, "NIP": str}) | |
db.sort_values(by=["Nama Lengkap"], inplace=True) | |
# Paging per Item, Image Downloader | |
items_per_page = 2 | |
pages_items = [] | |
page_items = [] | |
counter = 0 | |
for idx, item in db.iterrows(): | |
## Pic grabber | |
nip = item["NIP"] | |
formal_pic = item["Pas foto formal"] | |
if type(formal_pic) == str: | |
pic_downloader(formal_pic, nip + "_formal.jpg") | |
selfie_pic = item["Foto selfie gaya bebas"] | |
if type(selfie_pic) == str: | |
pic_downloader(selfie_pic, nip + "_selfie.jpg") | |
## Pagination | |
page_items.append(item) | |
counter += 1 | |
if counter % items_per_page == 0: | |
pages_items.append(page_items) | |
page_items = [] | |
# HTML Generator | |
from string import Template | |
import time | |
item_template = Template(open("item.html").read()) | |
page_template = Template(open("page.html").read()) | |
index_template = Template(open("index.html").read()) | |
pages_html = "" | |
for page_items in pages_items: | |
items_html = "" | |
for item in page_items: | |
nip = item["NIP"] | |
items_html += item_template.safe_substitute( | |
fullname=item["Nama Lengkap"], | |
nickname=item["Nama Panggilan (Boleh lebih dari satu)"], | |
nip=item["NIP"], | |
position=item["Penempatan"], | |
formation=item["Formasi"], | |
phonenumber=item["Nomor Hape"], | |
socialmedia=item["Akun Sosmed"], | |
moto=item["Moto"], | |
hoby=item["Hobi"], | |
description=item["Deskripsi singkat tentang Anda"], | |
formalpic=nip + "_formal.jpg", | |
selfiepic=nip + "_selfie.jpg" | |
) | |
pages_html += page_template.safe_substitute(items=items_html) | |
version_number = time.strftime("%Y%m%d-%H%M%S", time.localtime()) | |
index_html = index_template.safe_substitute(biodata=pages_html, version=version_number) | |
output_file = open("output.html", "w") | |
output_file.write(index_html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/paper-css/0.3.0/paper.css"> | |
<title>CPNS BKN 2017</title> | |
<style> | |
body { | |
font-size: 8pt; | |
} | |
@page { size: A5 } | |
.cpns { | |
} | |
.cpns-table { | |
border: 1px solid black; | |
} | |
.column-title { | |
width: 20%; | |
font-weight: bold; | |
} | |
.foto { | |
width: 25%; | |
background-color: #fffff0; | |
height: 150px; | |
border: 1px solid black; | |
} | |
.foto img { | |
width: 125px; | |
height: 175px; | |
} | |
.full-name { | |
background-color: #4472c4; | |
color: #ffffff; | |
font-size: 150%; | |
} | |
.biodata { | |
background-color: #d5dce4; | |
} | |
.description { | |
border: 1px solid black; | |
height: 100px; | |
} | |
.quote { | |
text-align: center; | |
font-size: 125%; | |
} | |
.title-page { | |
font-size: 150%; | |
background-color: #d5dce4; | |
} | |
</style> | |
</head> | |
<body class="A5"> | |
<section class="sheet padding-10mm title-page"> | |
<h1>Buku Angkatan<br> | |
Calon Pegawai Negeri Sipil (CPNS)<br> | |
Badan Kepegawaian Negara</h1> | |
<h3>Tahun 2017</h3> | |
<br/> | |
<br/> | |
<br/> | |
<p> | |
<b>Prototipe oleh: </b> Putu Wiramaswara Widya<br> | |
<i>Draf oto-bangun ALPHA versi $version</i> | |
</p> | |
<p><small>Buku Angkatan ini dibangun secara otomatis menggunakan HTML5 dan Python. Skrip dapat diunduh melalui </small></p> | |
</section> | |
$biodata | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="cpns"> | |
<table class="cpns-table"> | |
<tr> | |
<th colspan="4" class="full-name">$fullname</th> | |
</tr> | |
<tr class="biodata quote"> | |
<td colspan="4">“$moto”</td> | |
</tr> | |
<tr class="biodata"> | |
<td rowspan="7" class="foto"> | |
<img src="img/$formalpic"></img> | |
</td> | |
<td class="column-title">Panggilan</td> | |
<td>$nickname</td> | |
<td rowspan="7" class="foto"> | |
<img src="img/$selfiepic"></img> | |
</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">NIP</td> | |
<td>$nip</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">Penempatan</td> | |
<td>$position</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">Formasi</td> | |
<td>$formation</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">Nomor HP</td> | |
<td>$phonenumber</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">Akun Medsos</td> | |
<td>$socialmedia</td> | |
</tr> | |
<tr class="biodata"> | |
<td class="column-title">Hobi</td> | |
<td>$hoby</td> | |
</tr> | |
<tr> | |
<td colspan="4" class="description"> | |
$description | |
</td> | |
</tr> | |
</table> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section class="sheet padding-10mm"> | |
$items | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment