Skip to content

Instantly share code, notes, and snippets.

@WhiteCat6142
Last active July 26, 2021 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WhiteCat6142/1a536abb4f5ea2e638595a4de4011a52 to your computer and use it in GitHub Desktop.
Save WhiteCat6142/1a536abb4f5ea2e638595a4de4011a52 to your computer and use it in GitHub Desktop.
supermoon.py ver 1.1
"""
MIT License
Copyright 2021 Whitecat6142
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
"""
supermoon.py ver 1.2
supermoonはmoonlightに似たスレッド自動ロード機能です。
moonlightとは異なり対象となるノードをスーパーノード(主に公開ゲートウェイ)に限定し、
かつ日付やスレッドタイトルで絞り込むことで安全に使用できるようになっています。
このバージョンは朔APIを利用しています。
usage:
1.このファイルをsupermoon.pyとしてダウンロードする(実行権限の付与も忘れずに)
2.各種オプション(get_range,nodes,bantitle,mynode)を設定する
3.以下のコマンドを実行(bashの場合)
python3 ./supermoon.py
4.必要であればcronなどに上記コマンドを登録して定期実行させる
"""
import csv
import time
import http.client
import re
# need latest update:90days default
get_range=90*24*60*60
nodes=["https://bbs.shingetsu.info","http://shingetu.0g0.jp:8000","http://rep4649.ddo.jp:8000"]
bantitle=r"画像|admin"
mynode="localhost:8000"
def main():
t=set()
for n in nodes:
node=n.split("://", maxsplit=1)
conn0={}
if node[0]=="https":
conn0=http.client.HTTPSConnection(node[1],timeout=100)
elif node[0]=="http":
conn0=http.client.HTTPConnection(node[1],timeout=100)
else:
print("invaild prefix")
return
conn0.request("GET", "/gateway.cgi/csv/index/file,stamp,date,path,uri,type,title,records,size")
s=conn0.getresponse().read().decode("utf-8")
conn0.close()
f=s.splitlines()
l=csv.reader(f)
try:
search(l,t)
except Exception:
print(f"fail to connect to {n}")
try:
load(t)
except Exception:
print(f"connot find {mynode}")
def search(l,t):
target_time=time.time()-get_range
for row in l:
if (int(row[1])> target_time):
title = row[3]
if re.search(bantitle, row[6]):
pass
else:
if not (title in t):
print(row[6])
t.add(title)
return t
def load(t):
conn = http.client.HTTPConnection(mynode,timeout=100)
conn.request("GET", "/gateway.cgi/csv/index/file,stamp,date,path,uri,type,title,records,size")
s=conn.getresponse().read().decode("utf-8")
f=s.splitlines()
l=csv.reader(f)
for row in l:
t.discard(row[3])
for title in t:
conn.request("GET", f"{title}?search_new_file=yes")
res = conn.getresponse()
while chunk := res.read(512):
pass
print(res.status)
time.sleep(1)
conn.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment