-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
daemon_get_rss.py
185 lines (175 loc) · 6.65 KB
/
daemon_get_rss.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
__filename__ = "daemon_get_rss.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "[email protected]"
__status__ = "Production"
__module_group__ = "Core GET"
import os
from utils import data_dir
from utils import is_account_dir
from utils import acct_dir
from session import establish_session
from blog import html_blog_page_rss2
from blog import html_blog_page_rss3
from httpheaders import set_headers
from httpcodes import write2
from httpcodes import http_404
from fitnessFunctions import fitness_performance
from newswire import rss2header
from newswire import rss2footer
def get_rss2feed(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain: str, port: int, proxy_type: str,
getreq_start_time, debug: bool,
curr_session,
max_posts_in_rss_feed: int,
translate: {},
system_language: str,
fitness: {}) -> None:
"""Returns an RSS2 feed for the blog
"""
nickname = path.split('/blog/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if not nickname.startswith('rss.'):
account_dir = acct_dir(base_dir, nickname, domain)
if os.path.isdir(account_dir):
curr_session = \
establish_session("RSS request",
curr_session,
proxy_type,
self.server)
if not curr_session:
return
msg = \
html_blog_page_rss2(base_dir,
http_prefix,
translate,
nickname,
domain,
port,
max_posts_in_rss_feed, 1,
True,
system_language)
if msg is not None:
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/xml', msglen,
None, calling_domain, True)
write2(self, msg)
if debug:
print('Sent rss2 feed: ' +
path + ' ' + calling_domain)
fitness_performance(getreq_start_time, fitness,
'_GET', '_get_rss2feed',
debug)
return
if debug:
print('Failed to get rss2 feed: ' +
path + ' ' + calling_domain)
http_404(self, 22)
def get_rss2site(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain_full: str, port: int, proxy_type: str,
translate: {},
getreq_start_time,
debug: bool,
curr_session,
max_posts_in_rss_feed: int,
system_language: str,
fitness: {}) -> None:
"""Returns an RSS2 feed for all blogs on this instance
"""
curr_session = \
establish_session("get_rss2site",
curr_session,
proxy_type,
self.server)
if not curr_session:
http_404(self, 23)
return
msg = ''
dir_str = data_dir(base_dir)
for _, dirs, _ in os.walk(dir_str):
for acct in dirs:
if not is_account_dir(acct):
continue
nickname = acct.split('@')[0]
domain = acct.split('@')[1]
msg += \
html_blog_page_rss2(base_dir,
http_prefix,
translate,
nickname,
domain,
port,
max_posts_in_rss_feed, 1,
False,
system_language)
break
if msg:
msg = rss2header(http_prefix,
'news', domain_full,
'Site', translate) + msg + rss2footer()
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/xml', msglen,
None, calling_domain, True)
write2(self, msg)
if debug:
print('Sent rss2 feed: ' +
path + ' ' + calling_domain)
fitness_performance(getreq_start_time, fitness,
'_GET', '_get_rss2site',
debug)
return
if debug:
print('Failed to get rss2 feed: ' +
path + ' ' + calling_domain)
http_404(self, 24)
def get_rss3feed(self, calling_domain: str, path: str,
base_dir: str, http_prefix: str,
domain: str, port: int, proxy_type: str,
getreq_start_time,
debug: bool, system_language: str,
curr_session,
max_posts_in_rss_feed: int,
fitness: {}) -> None:
"""Returns an RSS3 feed
"""
nickname = path.split('/blog/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if not nickname.startswith('rss.'):
account_dir = acct_dir(base_dir, nickname, domain)
if os.path.isdir(account_dir):
curr_session = \
establish_session("get_rss3feed",
curr_session, proxy_type,
self.server)
if not curr_session:
http_404(self, 29)
return
msg = \
html_blog_page_rss3(base_dir, http_prefix,
nickname, domain, port,
max_posts_in_rss_feed, 1,
system_language)
if msg is not None:
msg = msg.encode('utf-8')
msglen = len(msg)
set_headers(self, 'text/plain; charset=utf-8',
msglen, None, calling_domain, True)
write2(self, msg)
if debug:
print('Sent rss3 feed: ' +
path + ' ' + calling_domain)
fitness_performance(getreq_start_time, fitness,
'_GET', '_get_rss3feed', debug)
return
if debug:
print('Failed to get rss3 feed: ' +
path + ' ' + calling_domain)
http_404(self, 20)