First commit <3
This commit is contained in:
203
bookmarks
Executable file
203
bookmarks
Executable file
@@ -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((
|
||||||
|
'<html>\n'
|
||||||
|
'\t<head>\n'
|
||||||
|
'\t\t<title>Bookmarks - Daniel Cortes</title>\n'
|
||||||
|
))
|
||||||
|
|
||||||
|
f.write("""
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans;
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: #151517;
|
||||||
|
color: #daddee;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #8cd7aa;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding-bottom: .3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, a, ul {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
border: 0;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.categories{
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category {
|
||||||
|
padding: 1em;
|
||||||
|
margin: 1em;
|
||||||
|
flex-basis: 20%;
|
||||||
|
background-color: #18191c;
|
||||||
|
box-shadow: 3px 3px 10px black;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
""")
|
||||||
|
f.write((
|
||||||
|
'\t</head>\n'
|
||||||
|
'\t<body>\n'
|
||||||
|
'\t<h1>Bookmarks</h1>\n'
|
||||||
|
'\t\t<div class="categories">\n'
|
||||||
|
))
|
||||||
|
|
||||||
|
for category in bookmarks:
|
||||||
|
f.write(f'\t\t\t<div class="category">\n')
|
||||||
|
f.write(f'\t\t\t\t<h2>{category}</h2>\n')
|
||||||
|
|
||||||
|
f.write('\t\t\t\t<ul>\n')
|
||||||
|
for bookmark in bookmarks[category]:
|
||||||
|
f.write(f'\t\t\t\t\t<li><a href="https://{bookmark.url}">{bookmark.name}</a></li>\n')
|
||||||
|
|
||||||
|
f.write('\t\t\t\t</ul>\n')
|
||||||
|
f.write(f'\t\t\t</div>\n')
|
||||||
|
|
||||||
|
f.write((
|
||||||
|
'\t\t</div>\n'
|
||||||
|
'\t</body>\n'
|
||||||
|
'</html>\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()
|
||||||
|
|
||||||
37
bookmarks.b
Normal file
37
bookmarks.b
Normal file
@@ -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
|
||||||
128
bookmarks.html
Normal file
128
bookmarks.html
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Bookmarks - Daniel Cortes</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans;
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: #151517;
|
||||||
|
color: #daddee;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #8cd7aa;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
padding-bottom: .3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, a, ul {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
border: 0;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
padding-bottom: .5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.categories{
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category {
|
||||||
|
padding: 1em;
|
||||||
|
margin: 1em;
|
||||||
|
flex-basis: 20%;
|
||||||
|
background-color: #18191c;
|
||||||
|
box-shadow: 3px 3px 10px black;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Bookmarks</h1>
|
||||||
|
<div class="categories">
|
||||||
|
<div class="category">
|
||||||
|
<h2>articles</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://udacity.github.io/git-styleguide">Udacity Git Commit Message Style Guide</a></li>
|
||||||
|
<li><a href="https://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice/9554657">The Use of Multiple JFrames: Good or Bad Practice?</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>people blogs</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://sivers.org">Derek Sivers</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>agregators</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://news.ycombinator.com">hacker news</a></li>
|
||||||
|
<li><a href="https://lobste.rs">lobsters</a></li>
|
||||||
|
<li><a href="https://dev.to">dev.to</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>4chan</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://4chan.org">home</a></li>
|
||||||
|
<li><a href="https://4chan.org/wg/catalog">/wg/</a></li>
|
||||||
|
<li><a href="https://4channel.org/g/catalog">/g/</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>reddit</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://reddit.com">home</a></li>
|
||||||
|
<li><a href="https://reddit.com/r/unixporn">r/unixporn</a></li>
|
||||||
|
<li><a href="https://reddit.com/r/chile">r/chile</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>tools</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://github.com">github</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>downloads</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://rutracker.org">rutracker</a></li>
|
||||||
|
<li><a href="https://1337x.to">1337x</a></li>
|
||||||
|
<li><a href="https://rutor.info">rutor</a></li>
|
||||||
|
<li><a href="https://the-eye.eu">the-eye</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="category">
|
||||||
|
<h2>others</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://twitter.com">twitter</a></li>
|
||||||
|
<li><a href="https://whatsapp.com">whatsapp</a></li>
|
||||||
|
<li><a href="https://gametabs.net">gametabs</a></li>
|
||||||
|
<li><a href="https://youtube.com">youtube</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user