going-flying.com gemini git repository
3002eb566bcb96d1239b5ec490755430ad23ce30 - Matthew Ernisse - 1596036244
new post, fixes.
diff --git a/cgi-bin/vfdsay.py b/cgi-bin/vfdsay.py index 4485a0e..c531e43 100755 --- a/cgi-bin/vfdsay.py +++ b/cgi-bin/vfdsay.py @@ -50,10 +50,6 @@ if __name__ == '__main__': print('10 What would you like to say (24 chars max)?\r\n') sys.exit(0) - if len(qs) > 24: - print('50 Maximum line length is 24 characters.\r\n') - sys.exit(0) - try: qs = unquote(qs) list(map(unicodeCheck, qs)) @@ -61,6 +57,10 @@ if __name__ == '__main__': print(f'50 {e} in input\r\n') sys.exit(0) + if len(qs) > 24: + print('50 Maximum line length is 24 characters.\r\n') + sys.exit(0) + try: resp = requests.get( 'http://wy60.internal.ub3rgeek.net/update', @@ -94,5 +94,5 @@ ATH DISCONNECTED ``` -=> /~mernisse/01.gmi.gmi Return +=> /~mernisse/01.gmi Return ''') diff --git a/files/thoughts-to-gemini.py b/files/thoughts-to-gemini.py index 6c25365..e35218d 100755 --- a/files/thoughts-to-gemini.py +++ b/files/thoughts-to-gemini.py @@ -38,8 +38,7 @@ import time from bs4 import BeautifulSoup -entry_template = ''' -===>> [ {{ entry.date }} ] +entry_template = '''===>> [ {{ entry.date }} ] > {{ entry.message }} {% if 'attachment' in entry.keys() %} @@ -51,8 +50,7 @@ entry_template = ''' {% endif %} ''' -index_template = ''' -``` +index_template = '''``` _______ __ __ __ |_ _|| |--..-----..--.--..-----.| |--.| |_ .-----. | | | || _ || | || _ || || _||__ --| @@ -64,7 +62,6 @@ index_template = ''' {% for year in thoughts.years %} ## {{ year }} - {% for month in thoughts.byYear(year) %} ### {{ month }} {% for entry in thoughts.forMonth(year, month) %} @@ -88,12 +85,8 @@ class DeHTMLizer(object): self.links = [] for el in soup.find('body').contents: - if el.name is not None: - self.gemini += self.parseTag(el) + self.gemini += self.parseElement(el) - elif el.string is not None: - self.gemini += el.string - def __str__(self): if len(self.gemini) == 0: return '~ NO MESSAGE ~' @@ -107,7 +100,24 @@ class DeHTMLizer(object): return self.gemini + trailer + def parseElement(self, el): + ''' Parse an Element from BeautifulSoup, this will recursively + call parseTag on nested tags as needed. It also handles + the difference between a Tag and a NavigableString. + ''' + if el.name is not None: + return self.parseTag(el) + + elif el.string is not None: + return el.string + else: + return '' + def parseTag(self, tag): + # So, of the tags that I believe we'll encounter that we + # actually want to print, p and blockquote can have children + # tags. + nestable = ['blockquote', 'p'] noprint = ['style', 'script'] if tag.name == 'a': @@ -116,8 +126,19 @@ class DeHTMLizer(object): return f'«{tag.string}[{num}]»' - elif tag.name == 'blockquote': - return f'“{tag.string}”' + elif tag.name in nestable: + if hasattr(tag, 'contents'): + buf = '' + for el in tag.contents: + buf += self.parseElement(el) + + return buf + + else: + if tag.name == 'blockquote': + return f'“{tag.string}”' + + return tag.string elif tag.name in ['em', 'strong']: return f'*{tag.string}*' diff --git a/images/03/vfd1.jpg b/images/03/vfd1.jpg new file mode 100644 index 0000000..ec3d058 Binary files /dev/null and b/images/03/vfd1.jpg differ diff --git a/images/03/vfd2.jpg b/images/03/vfd2.jpg new file mode 100644 index 0000000..70b4026 Binary files /dev/null and b/images/03/vfd2.jpg differ diff --git a/users/mernisse/articles/03.gmi b/users/mernisse/articles/03.gmi new file mode 100644 index 0000000..6abaee8 --- /dev/null +++ b/users/mernisse/articles/03.gmi @@ -0,0 +1,37 @@ +--- +Title: I'm marking it down here, great success! +Date: 07/29/2020 11:11 + +First of all I just wanted to thank the community here for such a resounding +welcome. I think I announced the existence of this little capsule only a +touch over an hour ago to the mailing list and I've already had some great +feedback and a few of you have found the little toy. + +=> /images/03/vfd1.jpg +=> /images/03/vfd2.jpg + +Secondly, some errata. I made some changes on the gemlog renderer, it should +now properly unroll paragraphs to comply with the line-oriented nature of the +Gemini markup language (is there a proper title for the text/gemini stuff?). +If your client renders any of the gemlog posts funny please drop me a line. + +=> mailto:matt@going-flying.com matt@going-flying.com + +I also made some changes to the microblog parser. The way it was converting +HTML to the Gemini markup was missing a bunch of nested tags. I was hoping +BeautifulSoup would handle that a little more gracefully but it didn't. As +a result that whole thing should look a lot better and actually be complete +when compared to the HTTPS version of it. + +=> /thoughts/ Thoughts on Gemini +=> https://www.going-flying.com/thoughts/ Thoughts on HTTPS + +Finally, back to my little VFD toy. acdw was nice enough to point out that +it was throwing an error on way less than 24 characters. (The VFD is a 2 line, +24 character display, I use the first line to show the date and time of the +message and the second line is for you, dear reader). It turns out I was +checking the message length *before* I was unquoting it so 'Hello World' would +be 'Hello%20World' and therefore being longer than it would be when transmitted +to the display. That bug should be fixed now too. + +Thanks everyone for the warm welcome!