Python
mastodon
pawoo

pawoo.netから✗✗な画像を拾ってくるpythonスクリプト書いた

More than 1 year has passed since last update.


はじめに

なんか最近mastodonって流行ってない?pawoo.netっていうインスタンスができたんだって?どれどれ...

PAWOOOOOOOOOO!!!!!


機能

10秒おきにpublic timelineを取得してsensitive=Trueな画像をDLします。


erogazou_kibonnu.py


#!/usr/local/bin python
# -*- coding: UTF-8 -*-
from urllib.request import urlopen
from urllib.parse import urlparse
import json
import os
from time import sleep

_baseurl = 'https://pawoo.net'
_api_public = '/api/v1/timelines/public'

def main():
timeline = urlopen(''.join([_baseurl, _api_public])).read()
toots = json.loads(timeline.decode('utf-8'))

for toot in toots:
if toot['sensitive']:
for media in toot['media_attachments']:
url = media['url']
getUrl(url)
print(url + ' downloaded')
sleep(1)

def getUrl(url):
img = urlopen(url)
path = urlparse(url).path
with open(os.path.basename(path), 'wb') as f:
f.write(img.read())
img.close()

if __name__ == '__main__':
while True:
main()
sleep(10)