-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwtxt.el
103 lines (81 loc) · 2.67 KB
/
twtxt.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;;; twtxt.el --- Client twtxt
;; Author: DEADBLACKCLOVER <[email protected]>
;; Version: 0.1
;; URL: https://github.com/deadblackclover/twtxt-el
;; Package-Requires: ((emacs "25.1") (request "0.2.0"))
;; Copyright (c) 2020, DEADBLACKCLOVER. This file is
;; licensed under the GNU General Public License version 3 or later. See
;; the LICENSE file.
;;; Commentary:
;; twtxt is a decentralised, minimalist microblogging service for hackers.
;;; Code:
(require 'cl-lib)
(require 'request)
(defgroup twtxt nil
"Client twtxt"
:group 'twtxt)
(defvar twtxt-file "~/twtxt"
"Pafth to twtxt file.")
(defvar twtxt-following nil
"Following list.")
(defvar twtxt-timeline-list nil
"Timeline list.")
(defvar twtxt-username ""
"Temporary storage of username.")
(defun twtxt-get-datetime ()
"Getting date and time according to RFC 3339 standard."
(concat (format-time-string "%Y-%m-%dT%T")
((lambda (x)
(concat (substring x 0 3) ":" (substring x 3 5)))
(format-time-string "%z"))))
(defun twtxt-parse-text (text)
"Convert TEXT to list post."
(split-string text "\n"))
(defun twtxt-replace-tab (str)
"Replacing tabs with line breaks in STR."
(replace-regexp-in-string "\t" "\n" str))
(defun twtxt-sort-post (list)
"Sorting posts in LIST."
(sort list #'string>))
(defun twtxt-append-username (text)
"Append username in TEXT."
(mapcar (lambda (item)
(concat twtxt-username "\t" item))
(twtxt-parse-text text)))
(defun twtxt-push-text (text)
"Concatenate the resulting TEXT with the current list."
(setq twtxt-timeline-list (append twtxt-timeline-list (twtxt-append-username text))))
(defun twtxt-fetch (url)
"Getting text by URL."
(progn (request url
:parser 'buffer-string
:success (cl-function (lambda
(&key
data
&allow-other-keys)
(twtxt-push-text data))))))
(defun twtxt-fetch-list ()
"Getting a list of texts."
(mapcar (lambda (item)
(setq twtxt-username (concat "[[" (car (cdr item)) "][" (car item) "]]"))
(twtxt-fetch (car (cdr item)))) twtxt-following))
(defun twtxt-timeline-buffer (data)
"Create buffer and DATA recording."
(switch-to-buffer (get-buffer-create "*twtxt-timeline*"))
(mapcar (lambda (item)
(insert (twtxt-replace-tab item))
(insert "\n\n")) data)
(org-mode)
(beginning-of-buffer))
(defun twtxt-timeline ()
"View your timeline."
(interactive)
(twtxt-fetch-list)
(twtxt-timeline-buffer (twtxt-sort-post twtxt-timeline-list))
(setq twtxt-timeline-list nil))
(defun twtxt-post (post)
"POST a status update."
(interactive "sPost:")
(append-to-file (concat (twtxt-get-datetime) "\t" post "\n") nil twtxt-file))
(provide 'twtxt)
;;; twtxt.el ends here