πŸ“’ Actions Speak Louder Than Words!

Nenez9595 (bhgn 4)

Posted: Jul 9, 2021 | Reading time: 5 min
⚠️ Warning: This post is over a year old, the information may be out of date.
πŸ“’ I’ve moved to a new website. Please visit me at https://journal.robbi.my !
post

Bismillahirahmanirrahim..

Alhamdulillah dengan izin Allah aku berjaya membuat salinan penuh laman blog (nenez9595.blogspot.com) Allahyarham pensyarah aku iaitu Prof Dr Hj Sazali. Boleh baca penulisan bahagian 1, 2 dan 3 sekiranya berminat dengan perjalanan yang dah aku lalui sebelum berjaya buat salinan penuh laman blog beliau.

Oleh sebab clone / mirror yang aku telah cuba dan buat tu hasil dia tak berapa cantik dan cun, maka aku fikir aku kene fix kan kod python yang aku buat waktu cubaan plan C yang aku ceritakan pada bahagian 2

So lepas few attempt try-error, aku pun akhirnya dapat la cara nak pull keseluruhan artikel melalui collections of feeds (Feed RSS ni yang leceh, dia ada pattern tersendiri, nak citer pun payah). Pendek cerita aku berjaya la kumpulkan 125 URL feeds dan aku kene scrape 125 feed tu semua dan convert setiap artikel (blog post) kepada markdown. So inilah kod python yang aku buat tu:

# -*- coding: utf-8 -*-
# The MIT License (MIT)
# Copyright (c) 2021 robbinespu@gmail.com
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.

import feedparser
import os.path
import re
from markdownify import markdownify
from urllib.parse import urlparse
directory = './html/'

def main():
    # Opening file
    file1 = open('nenez9595_feeds.txt', 'r')
    count = 0
    print("Using for loop")
    for line in file1:
        count += 1
        print("Scraping rss feed {}- {}".format(count, line.strip()))
        feed = feedparser.parse(line.strip() )
        items = feed["items"]
        for item in items:
            time = item[ "published_parsed" ]
            title = item[ "title" ]
            slug_title = re.sub('[^a-zA-Z-]+', '-', item[ "title" ].lower())
            slug_timestamp = item["published"][0:10]
            year = str(time.tm_year)
            mon = str(time.tm_mon)
            day = str(time.tm_mday)
            clock= item[ "updated" ]
            link = item[ "link" ]
            fileName = slug_timestamp + '-' + slug_title + '.md'
            fileName = fileName.replace('/', '')
            file_path = os.path.join(directory, fileName)
            if not os.path.isdir(directory):
                os.mkdir(directory)
            f = open(file_path,'w')
            value = item["content"][0]['value']
            f.write('---\nlayout: post\ntitle: "' + title + '"\n')
            f.write('date: ' + clock + '\n')
            f.write('draft: false\ntype: blog\n')
            f.write('meta_img: image/hj_sazali_meta.jpg \n')
            f.write('conical: "'+ link +'" \n')
            f.write('slug: "'+ slug_title +'" \n')
            f.write('---\n')
            f.write(markdownify(value))
            f.write('\n\n >Original link: ['+link+']('+link+')\n')
            f.close()
        print('end')
    file1.close()

if __name__ == "__main__":
    main()

So skrip ni akan scraping RSS feeds tu dan buat makdown files sesiap untuk aku. Aku pun dah set conical, slug dan meta_img untuk templating usage nanti. Senang kerja aku dan buat meta data nanti.

Kemudian aku decide nak pickup Hugo untuk web static generator, maleh aku nak guna Jekyll. Dah la guna Ruby gems sana-sini pastu nak built punya la take time. Aku rasa klu nk build keseluruhan 3,061 posts ni mau setengah-hari baru siap kot (done perli Ruby dan Jekyll), so Hugo much better options untuk aku setup.

Eden pun coba la theme hugo-nanx2020 sebab aku tengok website nanx.me macm nice je, sesuai untuk academician macam arwah tapi sayangnya dia punya mobile display memang kelaut, sayang betul. kalau desktop view…cun je

Mirror - Wayback Machine

So aku pun mods la theme. Adjust sana-sini-sana-sini dan akhirnya aku dapat hasil yang aku rasa puas hati. Asal ringan dan mesra pengguna dah cukup memuaskan bagi aku. Ada lagi ruang-ruang improvement tapi lain kali lah.

So inilah hasil nya..tet-tedenggg!! Amacam simple dan nice kan?

Suara Hati Ayahku - nenez9595

So aku push la changes ni dan sekarang dah pun default display. Kat bahagian menu tentang tu aku letak la info skit (kalau nak tahu, pergi baca sana) dan aku plan nak letak galeri macam blog asal dan list outkan semua papers dan buku yang arwah pernah terbitkan pada menu Buku tu.

So itu jelah kot update aku. Sampai sini jelah catatan aku. Aku minta maaf guna bahasa pasar je, sebab aku seronok menulis macamni. Rasa macam tengah layan mendengar lawak yang sengaja Dr Hj Sazali throw untuk hilangkan mengantuk budak-budak dalam kelas Statistic dan Discrete mathematics pula. Ahh..itu semua kenangan

Akhir kata, terima kasih mendidik aku. Aku bukanlah berjaya sangat pun tetapi kata-kata arwah la buatkan aku kuat dan semangat nak habiskan degree dulu. Bro, aku tolak offer luar negara, aku tolak offer kerja oversea dan syarikat besar sebab nak habis kan degree taw. Tu cerita lama la. Interesting story, aku tak rapat pun dengah arwah sgt, mostly kami berjumpa di kelas atau terjumpa di luar. Aku pernah bantu dia secara tidak langsung dalam sebuah buku dia (aku takde credit dalam tu, tak payah check dan aku tak kisah pun).

Okey lah. Terima kasih semua! Wasalam..

Edit

Have some thoughts, discussion or feedback on this post?
IndieWeb Interactions

Below you can find the interactions that this page has had using Indieweb. Which means, you can mentioned this URL on any website that support WebMention. Have you written a response to this post? Let me know the URL:

((Do you use a website that do not set up with WebMention capabilities? You can use Comment Parade.)