“How do I back up my logs?” , Farhaan thought. I love to copy paste stuff but after a while it becomes very monotonous.
“Everything that can be automated, should be automated”
Having this mind I sat down , writing python script to automate this job. I figured out that the trick lies in creating a zim -wiki page else it is just a script to copy paste a file. But to read a log file and organize it in a nice way has a bit of trickery too. Whenever you log a file , the log file is saved on the basis of the channel name . I have started talking to this channel called #dgplug and its pretty cool.
ZimWiki needs to have its content in a definite format, and you have to ‘forcefully’ add some lines to every document. Lines in the script that do this are :
zim_file.write('Content-Type: text/x-zim-wiki\nWiki-Format: zim 0.4\n') ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('Creation-Date: '+'%Y-%m-%d'+'T'+'%H:%M:%S'+'+05:30') zim_file.write(st+'\n')
These lines tells that the document is of certain type and the rest to generate a time stamp, and the rest is just opening a file reading it and copying to the other file. Second beautiful part is the reading the log file. I feel you should look into the code it is really interesting.If you want to contribute to the above script or look into it please do it on my GitHub page.The link to my GitHub page is here.
Fork it and use it, If you don’t know about Zim-Wiki , read about it and moreover use it . A great man once said , “Information comes to you once and you shouldn’t let it go”
Did you find this article valuable?
Support Farhaan Bukhsh by becoming a sponsor. Any amount is appreciated!