Compare commits
5 Commits
5b675acd28
...
a6d961aba9
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | a6d961aba9 | |
Tim Van Baak | 8e2369eff9 | |
Tim Van Baak | 5d0c5b1ae3 | |
Tim Van Baak | 77ad88124f | |
Tim Van Baak | 1416c2e518 |
|
@ -176,6 +176,7 @@ def callback():
|
||||||
params = request.get_json()
|
params = request.get_json()
|
||||||
if 'source' not in params and 'itemid' not in params:
|
if 'source' not in params and 'itemid' not in params:
|
||||||
logger.error("Bad request params: {}".format(params))
|
logger.error("Bad request params: {}".format(params))
|
||||||
|
logger.info('Executing callback for {}/{}'.format(params['source'], params['itemid']))
|
||||||
sources.item_callback(params['source'], params['itemid'])
|
sources.item_callback(params['source'], params['itemid'])
|
||||||
return jsonify({})
|
return jsonify({})
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ def command_test(args):
|
||||||
)
|
)
|
||||||
for sf_name, sf_sources
|
for sf_name, sf_sources
|
||||||
in subfeeds.items()
|
in subfeeds.items()
|
||||||
)
|
) if subfeeds else ''
|
||||||
print(f'Inquisitor configured from {config_path}')
|
print(f'Inquisitor configured from {config_path}')
|
||||||
print(f' {CONFIG_DATA} = {data_path}')
|
print(f' {CONFIG_DATA} = {data_path}')
|
||||||
print(f' {CONFIG_SOURCES} = {source_path}')
|
print(f' {CONFIG_SOURCES} = {source_path}')
|
||||||
|
|
|
@ -104,6 +104,8 @@ class LinearCrawler:
|
||||||
class RedditScraper:
|
class RedditScraper:
|
||||||
"""
|
"""
|
||||||
An engine for generating items from subreddits.
|
An engine for generating items from subreddits.
|
||||||
|
Requires defining source, subreddit_name
|
||||||
|
fetch new with RedditScraper.fetch_new(state, __name__, reddit)
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_new(state, name, reddit):
|
def fetch_new(state, name, reddit):
|
||||||
|
@ -170,7 +172,7 @@ class RedditScraper:
|
||||||
def get_body(self, post):
|
def get_body(self, post):
|
||||||
parts = []
|
parts = []
|
||||||
if not post.is_self:
|
if not post.is_self:
|
||||||
parts.append(f'<a href="{post.url}">link post</a>')
|
parts.append(f'<i>link:</i> <a href="{post.url}">{post.url}</a>')
|
||||||
if hasattr(post, 'preview'):
|
if hasattr(post, 'preview'):
|
||||||
try:
|
try:
|
||||||
previews = post.preview['images'][0]['resolutions']
|
previews = post.preview['images'][0]['resolutions']
|
||||||
|
@ -179,6 +181,17 @@ class RedditScraper:
|
||||||
parts.append(f'<img src="{preview["url"]}">')
|
parts.append(f'<img src="{preview["url"]}">')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
if getattr(post, 'is_gallery', False):
|
||||||
|
try:
|
||||||
|
for gallery_item in post.gallery_data['items']:
|
||||||
|
media_id = gallery_item['media_id']
|
||||||
|
metadata = post.media_metadata[media_id]
|
||||||
|
small_previews = [p for p in metadata['p'] if p['x'] < 800]
|
||||||
|
preview = sorted(small_previews, key=lambda p:-p['x'])[0]
|
||||||
|
parts.append(f'<i>link:</i> <a href="{metadata["s"]["u"]}">{metadata["s"]["u"]}</a>')
|
||||||
|
parts.append(f'<img src="{preview["u"]}">')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
if post.selftext:
|
if post.selftext:
|
||||||
limit = post.selftext[1024:].find(' ')
|
limit = post.selftext[1024:].find(' ')
|
||||||
preview_body = post.selftext[:1024 + limit]
|
preview_body = post.selftext[:1024 + limit]
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
.item-info { color: rgba(0, 0, 0, 0.7); }
|
.item-info { color: rgba(0, 0, 0, 0.7); }
|
||||||
.readable-item img { max-width: 100%; }
|
.readable-item img { max-width: 100%; }
|
||||||
button, summary { cursor: pointer; }
|
button, summary { cursor: pointer; }
|
||||||
|
summary { display: block; }
|
||||||
summary:focus { outline: 1px dotted gray; }
|
summary:focus { outline: 1px dotted gray; }
|
||||||
.strikethru span, .strikethru p { text-decoration: line-through; }
|
.strikethru span, .strikethru p { text-decoration: line-through; }
|
||||||
.fade span, .fade p { color: rgba(0, 0, 0, 0.2); }
|
.fade span, .fade p { color: rgba(0, 0, 0, 0.2); }
|
||||||
|
@ -76,10 +77,11 @@
|
||||||
body: JSON.stringify({items: items}),
|
body: JSON.stringify({items: items}),
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
location.reload()
|
location.reload();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var callback = function (source, itemid) {
|
var callback = function (source, itemid) {
|
||||||
|
document.getElementById(source + "-" + itemid + "-callback").disabled = true;
|
||||||
fetch('/callback/', {
|
fetch('/callback/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -107,7 +109,7 @@
|
||||||
<p>{{item.body|safe}}</p>
|
<p>{{item.body|safe}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.callback %}
|
{% if item.callback %}
|
||||||
<p><button onclick="javascript:callback('{{item.source}}', '{{item.id}}')">Callback</button></p>
|
<p><button id="{{item.source}}-{{item.id}}-callback" onclick="javascript:callback('{{item.source}}', '{{item.id}}')">Callback</button></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</details>
|
</details>
|
||||||
{% else %}<span class="item-title">{{item.title}}</span><br>
|
{% else %}<span class="item-title">{{item.title}}</span><br>
|
||||||
|
|
Loading…
Reference in New Issue