From 8f13bc2dbe580e17290e3f3be61eeba9fb561a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Cort=C3=A9s?= Date: Sun, 27 Oct 2019 03:09:29 -0300 Subject: [PATCH] First commit <3 --- bookmarks | 203 +++++++++++++++++++++++++++++++++++++++++++++++++ bookmarks.b | 37 +++++++++ bookmarks.html | 128 +++++++++++++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100755 bookmarks create mode 100644 bookmarks.b create mode 100644 bookmarks.html diff --git a/bookmarks b/bookmarks new file mode 100755 index 0000000..3dd6a86 --- /dev/null +++ b/bookmarks @@ -0,0 +1,203 @@ +#!/usr/bin/env python3 + +import sys +import os +import re + +class Bookmark: + def __init__(self, name, url): + self.name = name + self.url = url + + def __str__(self): + return self.name + ' => ' + self.url + + def __repr__(self): + return self.__str__() + +#Bookmarks grouped by their category +bookmarks = {} + +def usage(): + print('Usage:') + print(' bookmarks') + print(' Prints to stdout all the saved bookmarks') + print(' bookmarks generate') + print(' Generates an HTML file with all the bookmarks saved') + print(' bookmarks get name') + print(' Shows the url of the bookmark with the name given') + print(' bookmarks add category name url') + print(' Creates a new bookmark with the category, name and url given') + print(' bookmarks remove name') + print(' Removes the bookmark with the name given') + +def parse(): + with open('bookmarks.b', 'r') as f: + category_regex = re.compile(r'^\[(.+)\]$') + bookmark_regex = re.compile(r'^(.+) => (.+)$') + + category = '' + for line in f: + is_category = category_regex.match(line) + if is_category: + category = is_category.group(1) + bookmarks[category] = [] + + is_bookmark = bookmark_regex.match(line) + if is_bookmark: + bookmarks[category].append(Bookmark(is_bookmark.group(1), is_bookmark.group(2))) + +def show(): + if len(sys.argv) == 3: + searched = sys.argv[2] + else: + searched = sys.argv[1] + + for category in bookmarks: + for bookmark in bookmarks[category]: + if bookmark.name == searched: + print(bookmark.url) + return + +def add(): + try: + bookmarks[sys.argv[2]].append(Bookmark(sys.argv[3], sys.argv[4])) + except: + bookmarks[sys.argv[2]] = [Bookmark(sys.argv[3], sys.argv[4])] + +def remove(): + searched = sys.argv[2] + for category in bookmarks: + for bookmark in bookmarks[category]: + if bookmark.name == searched: + bookmarks[category].remove(bookmark) + if len(bookmarks[category]) == 0: + del bookmarks[category] + return + +def save(): + with open('bookmarks.w', 'w') as f: + for category in bookmarks: + f.write(f'[{category}]\n') + for bookmark in bookmarks[category]: + f.write(f'{bookmark.name} => {bookmark.url}\n') + f.write('\n') + + os.replace('bookmarks.w', 'bookmarks.b') + +def generate(): + f = open('bookmarks.html', 'w') + + f.write(( + '\n' + '\t\n' + '\t\tBookmarks - Daniel Cortes\n' + )) + + f.write(""" + + """) + f.write(( + '\t\n' + '\t\n' + '\t

Bookmarks

\n' + '\t\t
\n' + )) + + for category in bookmarks: + f.write(f'\t\t\t
\n') + f.write(f'\t\t\t\t

{category}

\n') + + f.write('\t\t\t\t
    \n') + for bookmark in bookmarks[category]: + f.write(f'\t\t\t\t\t
  • {bookmark.name}
  • \n') + + f.write('\t\t\t\t
\n') + f.write(f'\t\t\t
\n') + + f.write(( + '\t\t
\n' + '\t\n' + '\n' + )) + + f.close() + +if __name__ == '__main__': + if len(sys.argv) == 1: + parse() + elif sys.argv[1] == 'help' or sys.argv[1] == '-h' or sys.argv[1] == '--help': + usage() + elif sys.argv[1] == 'generate': + parse() + generate() + elif sys.argv[1] == 'add' and len(sys.argv) >= 5: + parse() + add() + save() + elif sys.argv[1] == 'remove' and len(sys.argv) >= 3: + parse() + remove() + save() + elif sys.argv[1] == 'get': + parse() + show() + else: + parse() + show() + diff --git a/bookmarks.b b/bookmarks.b new file mode 100644 index 0000000..f62e2a6 --- /dev/null +++ b/bookmarks.b @@ -0,0 +1,37 @@ +[articles] +Udacity Git Commit Message Style Guide => udacity.github.io/git-styleguide +The Use of Multiple JFrames: Good or Bad Practice? => stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice/9554657 + +[people blogs] +Derek Sivers => sivers.org + +[agregators] +hacker news => news.ycombinator.com +lobsters => lobste.rs +dev.to => dev.to + +[4chan] +home => 4chan.org +/wg/ => 4chan.org/wg/catalog +/g/ => 4channel.org/g/catalog + +[reddit] +home => reddit.com +r/unixporn => reddit.com/r/unixporn +r/chile => reddit.com/r/chile +r/piracy=> reddit.com/r/Piracy + +[tools] +github => github.com + +[downloads] +rutracker => rutracker.org +1337x => 1337x.to +rutor => rutor.info +the-eye => the-eye.eu + +[others] +twitter => twitter.com +whatsapp => whatsapp.com +gametabs => gametabs.net +youtube => youtube.com diff --git a/bookmarks.html b/bookmarks.html new file mode 100644 index 0000000..8cbf1b4 --- /dev/null +++ b/bookmarks.html @@ -0,0 +1,128 @@ + + + Bookmarks - Daniel Cortes + + + + +

Bookmarks

+
+ +
+

people blogs

+ +
+
+

agregators

+ +
+
+

4chan

+ +
+
+

reddit

+ +
+
+

tools

+ +
+
+

downloads

+ +
+
+

others

+ +
+
+ +