!date
print('hello fun world')
# because we're lazy (you're partial to this to now) we'll put it in a function
# in beta.
# today i had to write a ton of html for this one thing.
Okay it wasn't a ton but it was like this confusing piece i have to write to post a blog so i can make my blog roll all drop down menu-y
so im going to write a thingy that make that bit of code for me so i can copy paste it in. in future developments maybe i'll be an adult about the whole thing and use javascript.
for now tho.
yolo.
blog_post_string = """
<a href="./blog/just_a_little_bit.html" target="_blank"><li>this one isn't about python</li></a>
"""
# it's a doozy
admittedly i just started whipping it together up there but i figure maybe it's better to show workflow. makes for better content at least. let's make it official.
that up there is a link to my latest blog post. if you haven't read it you should go back and read it right now before you keep going in this one because there's spoilers. the spoiler is that they have nothing to do with each other.
oh great your stuck here now.
we can change things to make that link work for us.
html_file = 'one_here.html'
slug = 'and one here'
blog_post_string = '<a href="./blog/{html_file}" target="_blank"><li>{slug}</li></a> '.format(html_file=html_file, slug=slug)
print(blog_post_string)
import pyperclip # this makes it easy to copy stuff to the clipboard.
def make_blog_html_post_thing_that_makes_my_life_easy(html_file, slug):
# the wonders of tab finish
# always document children
'''
this function takes the name of an html file or the path to one in string type
and the slug, a small descriptive text in string type and outputs the link
to copy and paste in new_blog.html
'''
# that's as plain as i can put it. will accept criticism for coffee
blog_post_string = '<a href="./blog/{html_file}" target="_blank"><li>{slug}</li></a> '.format(html_file=html_file, slug=slug)
pyperclip.copy(blog_post_string)
# always test
make_blog_html_post_thing_that_makes_my_life_easy('something.html',
'something')
<a href="./blog/something.html" target="_blank"><li>something</li></a>
what u can't tell here is that i pasted after i ran the function and it worked.
hooray
there ya go. i made a thing. as far as thing's go, that's pretty simple. now to actually make it effective i will have to write it into it's own python file that does things and then probably make a command line alias for it. this also is still manual to a point, where i have to go still click into the right place in the blog roll html file.
obviously this is already getting out of hand.
the command line argument can come later.
next time...follow me as i
below is a little bit
bye
from bs4 import BeautifulSoup as bs
from bs4 import Comment
html = '../new_blog.html'
html = open(html, 'r')
a = []
soup = bs(html, 'html.parser')
comments = soup.find_all(string=lambda text: isinstance(text, Comment))
# lambdas is what you get when you copy paste stack over flow code
for c in comments:
print(c)
print("=============")
a = c.extract()
that's right. u see sublists. O_o
pyperclip
is an external library that this guy wrote
BeautifulSoup
has nothing to do with soup and helps programmers take apart html files and stuff can be found here about it.
the code from above was copied from here. i kind of understand it, but :P