Compare commits
43 Commits
74a8f3bfe7
...
master
Author | SHA1 | Date | |
---|---|---|---|
97a315d2d1 | |||
b29cf737a7 | |||
51a37c4562 | |||
34a3f06d91 | |||
f92d59dd91 | |||
e3cdce4f12 | |||
f449305ccd | |||
1b252ca2c7 | |||
9aee38bc50 | |||
e709a2ade1 | |||
359407187e | |||
90fc695794 | |||
0038eecfbc | |||
7eddd9b9d7 | |||
3c49d4ecd1 | |||
5cbcb2e6f2 | |||
c92c8b368f | |||
2e71e2d6db | |||
9de4990d69 | |||
ef88dad4a8 | |||
1259db8212 | |||
eec79067d8 | |||
5676bf4735 | |||
b3364d99b0 | |||
fec0ee4b10 | |||
cc274a5d96 | |||
45809ff5ec | |||
3fa1bb4c92 | |||
125528c567 | |||
a44082180c | |||
c018534c0e | |||
bb67f98d4b | |||
b06a606fd7 | |||
5ed96b0ddf | |||
c875a4a17d | |||
2cb3eec4aa | |||
818110e485 | |||
428814b318 | |||
a291010ae1 | |||
e6f8dbd1e8 | |||
7009169145 | |||
bd5621f9bd | |||
ad96b14445 |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#### stupidly easy IRC bot written in python(3)
|
#### stupidly easy IRC bot written in python(3)
|
||||||
I wrote this bot over the course of the last year. It grew and new function were added every now and then.<br>
|
I wrote this bot over the course of the last year. It grew and new function were added every now and then.<br>
|
||||||
The code is pretty ugly and the bot has some serious problems with memory leaks and random disconnects and lacks an automatic rejoin function.
|
The code is pretty ugly and lacks an automatic rejoin function.
|
||||||
|
|
||||||
But overall it is a pretty fun thing and is heavily used on the IRC server that I am currently using (n0xy.net).
|
But overall it is a pretty fun thing and is heavily used on the IRC server that I am currently using (n0xy.net).
|
||||||
|
|
||||||
@ -15,15 +15,11 @@ But overall it is a pretty fun thing and is heavily used on the IRC server that
|
|||||||
|.eurusd \<value\>|convert euro to usd|
|
|.eurusd \<value\>|convert euro to usd|
|
||||||
|.usdeur \<value\>|convert usd to euro|
|
|.usdeur \<value\>|convert usd to euro|
|
||||||
|.jn \<question\>|choose between yes or no|
|
|.jn \<question\>|choose between yes or no|
|
||||||
|.twitter \<account\>|get the last tweet of \<account\>|
|
|
||||||
|.trump|get trumps last tweet|
|
|
||||||
|.konfuzius|get a konfuzius quote (in german from wikiquote)|
|
|.konfuzius|get a konfuzius quote (in german from wikiquote)|
|
||||||
|.say \<message\>|make the bot say something (only for admin user)|
|
|.say \<message\>|make the bot say something (only for admin user)|
|
||||||
|.fml|get a random fml from fmylife.com|
|
|.fml|get a random fml from fmylife.com|
|
||||||
|.nslookup \<domain\> (\<type\>)|make a dns lookup for \<domain\> with optional \<type\>|
|
|.nslookup \<domain\> (\<type\>)|make a dns lookup for \<domain\> with optional \<type\>|
|
||||||
|
|
||||||
##### automatic triggers
|
##### automatic triggers
|
||||||
- All http links are parsed and the html title is printed out if one is found
|
|
||||||
- The bot automatically parses all twitter links and prints out the full tweet and account name.
|
|
||||||
- The blog of the german blogger "fefe" (Felix von Leitner - blog.fefe.de) is crawled every five mins. and new Posts are automatically printed out with a link to the post
|
- The blog of the german blogger "fefe" (Felix von Leitner - blog.fefe.de) is crawled every five mins. and new Posts are automatically printed out with a link to the post
|
||||||
|
|
||||||
|
228
bert.py
228
bert.py
@ -1,45 +1,33 @@
|
|||||||
#!/usr/bin/python3 -u
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
import gc
|
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import launch
|
import launch
|
||||||
import tweepy
|
|
||||||
import threading
|
import threading
|
||||||
import re
|
import re
|
||||||
import html
|
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from datetime import timedelta
|
|
||||||
import konfuzius
|
import konfuzius
|
||||||
import urlinfo
|
|
||||||
import fml
|
import fml
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
from flask import Flask, request
|
|
||||||
from nslookup import nslookup
|
from nslookup import nslookup
|
||||||
import rss
|
import rss
|
||||||
|
|
||||||
version = "v0.8"
|
version = "v0.9"
|
||||||
|
|
||||||
# IRC settings
|
# IRC settings
|
||||||
host = ""
|
host = ""
|
||||||
port =
|
port =
|
||||||
nick = "bert"
|
nick = "huan"
|
||||||
password = ""
|
password = ""
|
||||||
chan = ""
|
chan = ""
|
||||||
fefe_chans = [""]
|
fefe_chans = [""]
|
||||||
|
|
||||||
# Twitter settings
|
|
||||||
consumer_key = ""
|
|
||||||
consumer_secret = ""
|
|
||||||
access_token = ""
|
|
||||||
access_secret = ""
|
|
||||||
|
|
||||||
# fml endpoint
|
# fml endpoint
|
||||||
fml_url = "http://www.fmylife.com/random"
|
fml_url = "http://www.fmylife.com/random"
|
||||||
|
|
||||||
@ -50,10 +38,8 @@ y = "\x038"
|
|||||||
r = "\x034"
|
r = "\x034"
|
||||||
g = "\x033"
|
g = "\x033"
|
||||||
|
|
||||||
|
# global variable for the socket, see connect()
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
irc = None
|
||||||
irc = ssl.wrap_socket(s)
|
|
||||||
|
|
||||||
|
|
||||||
# Currency API
|
# Currency API
|
||||||
def get_exchange():
|
def get_exchange():
|
||||||
@ -83,11 +69,11 @@ def safeexit():
|
|||||||
|
|
||||||
|
|
||||||
def connect(host, port):
|
def connect(host, port):
|
||||||
|
global irc
|
||||||
print("Connecting to "+host+":"+str(port))
|
print("Connecting to "+host+":"+str(port))
|
||||||
try:
|
context = ssl.create_default_context()
|
||||||
irc.connect((host, port))
|
with socket.create_connection((host, port), timeout=180) as sock:
|
||||||
except Exception as err:
|
irc = context.wrap_socket(sock, server_hostname=host)
|
||||||
print("Connection failed! "+err)
|
|
||||||
|
|
||||||
|
|
||||||
def sendRaw(data):
|
def sendRaw(data):
|
||||||
@ -96,26 +82,17 @@ def sendRaw(data):
|
|||||||
|
|
||||||
def register(nick, host):
|
def register(nick, host):
|
||||||
print("Registering User...")
|
print("Registering User...")
|
||||||
try:
|
sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
|
||||||
sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
|
|
||||||
except Exception as err:
|
|
||||||
print("Failed! "+err)
|
|
||||||
|
|
||||||
|
|
||||||
def name(nick):
|
def name(nick):
|
||||||
print("Setting Nickname to "+nick)
|
print("Setting Nickname to "+nick)
|
||||||
try:
|
sendRaw("NICK "+nick+"\n")
|
||||||
sendRaw("NICK "+nick+"\n")
|
|
||||||
except Exception as err:
|
|
||||||
print("Failed! "+err)
|
|
||||||
|
|
||||||
|
|
||||||
def auth(nick, password):
|
def auth(nick, password):
|
||||||
print("Authenticating...")
|
print("Authenticating...")
|
||||||
try:
|
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
|
||||||
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
|
|
||||||
except Exception as err:
|
|
||||||
print(err)
|
|
||||||
|
|
||||||
|
|
||||||
def join(chan):
|
def join(chan):
|
||||||
@ -123,15 +100,12 @@ def join(chan):
|
|||||||
try:
|
try:
|
||||||
sendRaw("JOIN "+chan+"\n")
|
sendRaw("JOIN "+chan+"\n")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print("Failed! "+err)
|
print("Failed! "+str(err))
|
||||||
|
|
||||||
|
|
||||||
def mode(nick):
|
def mode(nick):
|
||||||
print("Setting mode +B")
|
print("Setting modes +B-x")
|
||||||
try:
|
sendRaw("MODE "+nick+" +B-x\n")
|
||||||
sendRaw("MODE "+nick+" +B\n")
|
|
||||||
except Exception as err:
|
|
||||||
print("Failed! "+err)
|
|
||||||
|
|
||||||
|
|
||||||
def part(chan):
|
def part(chan):
|
||||||
@ -147,7 +121,7 @@ def say(chan, msg):
|
|||||||
sendRaw("PRIVMSG "+chan+" :"+msg+"\n")
|
sendRaw("PRIVMSG "+chan+" :"+msg+"\n")
|
||||||
print("OK")
|
print("OK")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print("Error: "+err)
|
print("Error: "+str(err))
|
||||||
|
|
||||||
|
|
||||||
def raw(msg):
|
def raw(msg):
|
||||||
@ -162,11 +136,18 @@ def me(chan, msg):
|
|||||||
try:
|
try:
|
||||||
sendRaw("PRIVMSG "+chan+" :\u0001ACTION "+msg+"\u0001\n")
|
sendRaw("PRIVMSG "+chan+" :\u0001ACTION "+msg+"\u0001\n")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print("Error: "+err)
|
print("Error: "+str(err))
|
||||||
|
|
||||||
|
|
||||||
def getData():
|
def getData():
|
||||||
raw = irc.recv(4096)
|
try:
|
||||||
|
raw = irc.recv(4096)
|
||||||
|
except TimeoutError:
|
||||||
|
print("Connection timed out!")
|
||||||
|
sys.exit(0)
|
||||||
|
if not raw:
|
||||||
|
print("Connection lost!")
|
||||||
|
sys.exit(0)
|
||||||
try:
|
try:
|
||||||
data = raw.decode("UTF-8")
|
data = raw.decode("UTF-8")
|
||||||
except:
|
except:
|
||||||
@ -184,8 +165,8 @@ def getMessage():
|
|||||||
|
|
||||||
|
|
||||||
def getRocket():
|
def getRocket():
|
||||||
rocket, mission, status, delta = launch.next_launch()
|
rocket, mission, delta = launch.next_launch()
|
||||||
rstring = "%sNext rocket: %s%s %s| %s%s %s| %sStatus: %s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, status, b, y, delta)
|
rstring = "%sNext rocket: %s%s %s| %s%s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, delta)
|
||||||
return rstring
|
return rstring
|
||||||
|
|
||||||
|
|
||||||
@ -195,19 +176,13 @@ def yon():
|
|||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
|
||||||
def url_title(url):
|
|
||||||
title = urlinfo.get_title(url).encode("UTF-8").decode("UTF-8")
|
|
||||||
return title
|
|
||||||
|
|
||||||
|
|
||||||
def is_registered(username):
|
def is_registered(username):
|
||||||
try:
|
try:
|
||||||
sendRaw("WHOIS "+str(username)+"\n")
|
sendRaw("WHOIS "+str(username)+"\n")
|
||||||
user_info = getMessage()
|
user_info = getMessage()
|
||||||
regex = r"330 "+str(nick)+" "+str(username)+" [a-zA-Z0-9]+ :is logged in as"
|
regex = rf"330 {str(re.escape(nick))} {str(re.escape(username))} \S+ :is logged in as"
|
||||||
matches = re.finditer(regex, user_info, re.MULTILINE)
|
matches = re.finditer(regex, user_info, re.MULTILINE)
|
||||||
for match in matches:
|
for match in matches:
|
||||||
print(match.group(0))
|
|
||||||
acc_name = match.group(0).split()[3]
|
acc_name = match.group(0).split()[3]
|
||||||
return acc_name
|
return acc_name
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -271,32 +246,26 @@ def ping(msg):
|
|||||||
sendRaw("PONG :"+msg+"\n")
|
sendRaw("PONG :"+msg+"\n")
|
||||||
|
|
||||||
|
|
||||||
def start(host, port, nick, password, chan):
|
def start(host, port, nick, password, chans):
|
||||||
try:
|
connect(host, port)
|
||||||
connect(host, port)
|
sleep(2)
|
||||||
sleep(2)
|
register(nick, host)
|
||||||
register(nick, host)
|
sleep(2)
|
||||||
sleep(2)
|
name(nick)
|
||||||
name(nick)
|
sleep(6)
|
||||||
sleep(6)
|
auth(nick, password)
|
||||||
auth(nick, password)
|
sleep(2)
|
||||||
sleep(2)
|
mode(nick)
|
||||||
for chan in fefe_chans:
|
sleep(2)
|
||||||
join(chan)
|
for chan in chans:
|
||||||
sleep(2)
|
join(chan)
|
||||||
mode(nick)
|
sleep(2)
|
||||||
sleep(2)
|
|
||||||
except Exception as err:
|
|
||||||
print("FAIL: "+err)
|
|
||||||
|
|
||||||
|
|
||||||
def command_loop():
|
def command_loop():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
data = getData()
|
data = getData()
|
||||||
with open("bert.log", "a") as f:
|
|
||||||
f.write(data)
|
|
||||||
f.close()
|
|
||||||
ircmsg = data.strip("\n\r")
|
ircmsg = data.strip("\n\r")
|
||||||
if ircmsg.find("PING :") != -1:
|
if ircmsg.find("PING :") != -1:
|
||||||
pingstring = ircmsg.strip("PING :")
|
pingstring = ircmsg.strip("PING :")
|
||||||
@ -314,7 +283,7 @@ def command_loop():
|
|||||||
print("direct message received")
|
print("direct message received")
|
||||||
if msg == "\x01VERSION\x01":
|
if msg == "\x01VERSION\x01":
|
||||||
print("got ctcp version request")
|
print("got ctcp version request")
|
||||||
notice(ircnick, "\x01VERSION BertBot "+version+"\x01")
|
notice(ircnick, "\x01VERSION HuanBot (fork of BertBot) "+version+"\x01")
|
||||||
elif msg.startswith("\x01PING"):
|
elif msg.startswith("\x01PING"):
|
||||||
print("got ctcp ping request")
|
print("got ctcp ping request")
|
||||||
pingstring = msg.split()[1]
|
pingstring = msg.split()[1]
|
||||||
@ -326,7 +295,7 @@ def command_loop():
|
|||||||
|
|
||||||
elif msg == ".help":
|
elif msg == ".help":
|
||||||
print("sending help")
|
print("sending help")
|
||||||
say(channel, "available commands: .nextrocket, .slap, .mate, .jn, .rep, .twitter, .trump, .konfuzius, .fml, .eurusd, .usdeur, .nslookup")
|
say(channel, "available commands: .nextrocket, .slap, .mate, .hello, .jn, .rep, .konfuzius, .fml, .eurusd, .usdeur, .nslookup")
|
||||||
|
|
||||||
elif msg == ".nextrocket":
|
elif msg == ".nextrocket":
|
||||||
try:
|
try:
|
||||||
@ -396,14 +365,14 @@ def command_loop():
|
|||||||
except:
|
except:
|
||||||
reason = "None"
|
reason = "None"
|
||||||
print("with no reason")
|
print("with no reason")
|
||||||
if user == ircnick:
|
|
||||||
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
acc_name = is_registered(user)
|
acc_name = is_registered(user)
|
||||||
give_acc = is_registered(ircnick)
|
give_acc = is_registered(ircnick)
|
||||||
print("found account name for "+str(user)+": "+str(acc_name))
|
print("found account name for "+str(user)+": "+str(acc_name))
|
||||||
if acc_name != None and give_acc != None:
|
if acc_name != None and give_acc != None:
|
||||||
|
if acc_name == give_acc:
|
||||||
|
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
||||||
|
continue
|
||||||
give_rep(acc_name, user, give_acc, reason, channel)
|
give_rep(acc_name, user, give_acc, reason, channel)
|
||||||
elif give_acc == None:
|
elif give_acc == None:
|
||||||
say(channel, "You are not registered!")
|
say(channel, "You are not registered!")
|
||||||
@ -428,31 +397,6 @@ def command_loop():
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
print("Error getting rep! - "+str(err))
|
print("Error getting rep! - "+str(err))
|
||||||
|
|
||||||
elif msg.startswith(".twitter"):
|
|
||||||
try:
|
|
||||||
twittername = msg.split()[1]
|
|
||||||
try:
|
|
||||||
lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0]
|
|
||||||
twit = lasttweet.full_text
|
|
||||||
user = lasttweet.user.name
|
|
||||||
text = html.unescape(re.sub(r'\n', ' ', twit))
|
|
||||||
say(channel, b+user+": "+c+text)
|
|
||||||
except Exception as err:
|
|
||||||
print("Could not get last tweet! "+err)
|
|
||||||
except:
|
|
||||||
say(channel, "You have to give me a username")
|
|
||||||
|
|
||||||
elif msg.startswith(".trump"):
|
|
||||||
try:
|
|
||||||
twittername = "realdonaldtrump"
|
|
||||||
lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0]
|
|
||||||
twit = lasttweet.full_text
|
|
||||||
user = lasttweet.user.name
|
|
||||||
text = html.unescape(re.sub(r'\n', ' ', twit))
|
|
||||||
say(channel, b+user+": "+c+text)
|
|
||||||
except Exception as err:
|
|
||||||
print("Could not get last tweet! "+err)
|
|
||||||
|
|
||||||
elif msg.startswith(".konfuzius"):
|
elif msg.startswith(".konfuzius"):
|
||||||
try:
|
try:
|
||||||
quote = konfuzius.random_quote()
|
quote = konfuzius.random_quote()
|
||||||
@ -461,7 +405,7 @@ def command_loop():
|
|||||||
say(channel, "Error :(")
|
say(channel, "Error :(")
|
||||||
|
|
||||||
elif msg == ".quit":
|
elif msg == ".quit":
|
||||||
if ircnick == "elmo":
|
if ircnick == "jkhsjdhjs":
|
||||||
say(channel, "Flying to mars...")
|
say(channel, "Flying to mars...")
|
||||||
print("got quit command. exiting...")
|
print("got quit command. exiting...")
|
||||||
part(channel)
|
part(channel)
|
||||||
@ -470,7 +414,7 @@ def command_loop():
|
|||||||
say(channel, "You are not my master!")
|
say(channel, "You are not my master!")
|
||||||
|
|
||||||
elif msg.startswith(".say"):
|
elif msg.startswith(".say"):
|
||||||
if ircnick == "elmo":
|
if ircnick == "jkhsjdhjs":
|
||||||
try:
|
try:
|
||||||
sayit = msg.split(" ", 1)[1]
|
sayit = msg.split(" ", 1)[1]
|
||||||
say(channel, str(sayit))
|
say(channel, str(sayit))
|
||||||
@ -481,7 +425,7 @@ def command_loop():
|
|||||||
say(channel, "You are not my master!")
|
say(channel, "You are not my master!")
|
||||||
|
|
||||||
elif msg.startswith(".debug"):
|
elif msg.startswith(".debug"):
|
||||||
if ircnick == "elmo":
|
if ircnick == "jkhsjdhjs":
|
||||||
try:
|
try:
|
||||||
debugmsg = msg.split(" ", 1)[1]
|
debugmsg = msg.split(" ", 1)[1]
|
||||||
raw(debugmsg)
|
raw(debugmsg)
|
||||||
@ -491,30 +435,6 @@ def command_loop():
|
|||||||
else:
|
else:
|
||||||
say(channel, "You are not my master!")
|
say(channel, "You are not my master!")
|
||||||
|
|
||||||
elif "twitter.com" in msg:
|
|
||||||
try:
|
|
||||||
p = re.compile('twitter\.com/[A-Za-z0-9]*/status/[0-9]*')
|
|
||||||
tweet_link = p.search(msg).group(0)
|
|
||||||
status_id = tweet_link.split("/")[3]
|
|
||||||
status = api.get_status(status_id, tweet_mode="extended")
|
|
||||||
user = status.user.name
|
|
||||||
text = status.full_text
|
|
||||||
print("found twitter link\n"+user+" - "+text)
|
|
||||||
say(channel, b+user+": "+c+text)
|
|
||||||
except Exception as err:
|
|
||||||
print("twitter link invalid "+str(err))
|
|
||||||
elif urlinfo.is_url(msg) != None:
|
|
||||||
try:
|
|
||||||
url = urlinfo.is_url(msg)
|
|
||||||
ignore = ["pr0gramm", "w0bm", "f0ck", "twitter", "youtube", "youtu.be"]
|
|
||||||
if any(ign in url for ign in ignore):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
title = urlinfo.get_title(url)
|
|
||||||
print("Found URL and got title "+str(title))
|
|
||||||
say(channel, b+"Title: "+c+title)
|
|
||||||
except Exception as err:
|
|
||||||
print("Error getting URL title - "+str(err))
|
|
||||||
elif msg == ".fml":
|
elif msg == ".fml":
|
||||||
try:
|
try:
|
||||||
fml_string = fml.get_fml(fml_url)
|
fml_string = fml.get_fml(fml_url)
|
||||||
@ -530,13 +450,12 @@ def command_loop():
|
|||||||
except:
|
except:
|
||||||
say(channel, r+"You must specify a domain!")
|
say(channel, r+"You must specify a domain!")
|
||||||
continue
|
continue
|
||||||
try:
|
nstype = msg_parts[2:]
|
||||||
nstype = msg_parts[2]
|
if not nstype:
|
||||||
except:
|
nstype = ["AAAA", "A"]
|
||||||
nstype = "A"
|
|
||||||
print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype))
|
print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype))
|
||||||
nsresult = nslookup(nsdomain, nstype)
|
nsresult = nslookup(nsdomain, nstype)
|
||||||
nslines = nsresult.split("\n")
|
nslines = set(nsresult.split("\n"))
|
||||||
for nsline in nslines:
|
for nsline in nslines:
|
||||||
say(channel, y+" "+str(nsline))
|
say(channel, y+" "+str(nsline))
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -563,17 +482,6 @@ def fefe_check():
|
|||||||
sleep(300)
|
sleep(300)
|
||||||
|
|
||||||
|
|
||||||
def gc_cycle():
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
# fire the garbage collector
|
|
||||||
gc.set_debug(gc.DEBUG_STATS)
|
|
||||||
gc.collect()
|
|
||||||
time.sleep(120)
|
|
||||||
except Exception as err:
|
|
||||||
print("Error in garbage collector! - "+str(err))
|
|
||||||
|
|
||||||
|
|
||||||
class command_thread(threading.Thread):
|
class command_thread(threading.Thread):
|
||||||
def __init__(self, threadID):
|
def __init__(self, threadID):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@ -590,30 +498,18 @@ class fefe_thread(threading.Thread):
|
|||||||
print("Starting fefe thread...")
|
print("Starting fefe thread...")
|
||||||
fefe_check()
|
fefe_check()
|
||||||
|
|
||||||
class gc_thread(threading.Thread):
|
|
||||||
def __init__(self, threadID):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
self.threadID = threadID
|
|
||||||
def run(self):
|
|
||||||
print("Starting garbage collector thread...")
|
|
||||||
gc_cycle()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
start(host, port, nick, password, chan)
|
try:
|
||||||
global api
|
start(host, port, nick, password, set(join_chans + fefe_chans))
|
||||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
|
except Exception as err:
|
||||||
auth.set_access_token(access_token, access_secret)
|
print("FAIL: "+str(err))
|
||||||
api = tweepy.API(auth)
|
sys.exit(1)
|
||||||
thread_command = command_thread(1)
|
thread_command = command_thread(1)
|
||||||
thread_fefe = fefe_thread(2)
|
#thread_fefe = fefe_thread(2)
|
||||||
thread_gc = gc_thread(3)
|
|
||||||
thread_command.start()
|
thread_command.start()
|
||||||
sleep(2)
|
#sleep(2)
|
||||||
thread_fefe.start()
|
#thread_fefe.start()
|
||||||
sleep(2)
|
|
||||||
thread_gc.start()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
gc.enable()
|
|
||||||
main()
|
main()
|
||||||
|
6
fml.py
6
fml.py
@ -3,16 +3,12 @@
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
url = "http://www.fmylife.com/random"
|
|
||||||
|
|
||||||
|
|
||||||
def get_fml(url):
|
def get_fml(url):
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
data = r.text
|
data = r.text
|
||||||
r.close
|
r.close
|
||||||
soup = BeautifulSoup(data, 'html.parser')
|
soup = BeautifulSoup(data, 'html.parser')
|
||||||
fml = soup.find("article", class_="art-panel").find_all("a")[2].string.strip().replace("\\", "").replace(" FML", "")
|
fml = soup.select_one("article > a.block").string.strip().replace("\\", "").rstrip(" FML")
|
||||||
del soup
|
del soup
|
||||||
return fml
|
return fml
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
import json
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
59
launch.py
59
launch.py
@ -10,61 +10,34 @@ from string import Template
|
|||||||
b = "\x0312"
|
b = "\x0312"
|
||||||
y = "\x038"
|
y = "\x038"
|
||||||
|
|
||||||
API_URL = "https://launchlibrary.net/1.2/launch/next/1"
|
API_URL = "https://fdo.rocketlaunch.live/json/launches/next/1"
|
||||||
|
|
||||||
class launch(object):
|
class launch(object):
|
||||||
def api_request(self):
|
def api_request(self):
|
||||||
request = urllib.request.Request(API_URL)
|
request = urllib.request.Request(API_URL)
|
||||||
response = urllib.request.urlopen(request).read()
|
response = urllib.request.urlopen(request).read()
|
||||||
json_data = json.loads(response.decode('UTF-8'))
|
json_data = json.loads(response.decode('UTF-8'))
|
||||||
return json_data['launches'][0]
|
return json_data['result'][0]
|
||||||
|
|
||||||
def rocket_name(self, json_data):
|
def rocket_name(self, json_data):
|
||||||
try:
|
try:
|
||||||
name = json_data['rocket']['name']
|
name = json_data['vehicle']['name']
|
||||||
except:
|
except:
|
||||||
name = "UNKNOWN"
|
name = "UNKNOWN"
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def mission_name(self, json_data):
|
def mission_name(self, json_data):
|
||||||
try:
|
try:
|
||||||
name = json_data['missions'][0]['name']
|
name = json_data['name']
|
||||||
except:
|
except:
|
||||||
name = "UNKNOWN"
|
name = "UNKNOWN"
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def net_raw_utc(self, json_data):
|
def net_raw_utc(self, json_data):
|
||||||
time_utc_string = json_data['net']
|
time_utc_string = json_data['t0']
|
||||||
try:
|
time_utc = datetime.datetime.fromisoformat(time_utc_string)
|
||||||
time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')
|
|
||||||
except TypeError:
|
|
||||||
time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6]))
|
|
||||||
return time_utc
|
return time_utc
|
||||||
|
|
||||||
def net(self, json_data):
|
|
||||||
time_utc_string = json_data['net']
|
|
||||||
try:
|
|
||||||
time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')
|
|
||||||
except TypeError:
|
|
||||||
time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6]))
|
|
||||||
time_local = pytz.utc.localize(time_utc).astimezone(pytz.timezone('Europe/Berlin'))
|
|
||||||
time = datetime.datetime.strftime(time_local, 'NET %d.%m.%Y')
|
|
||||||
return time
|
|
||||||
|
|
||||||
def get_status(self, json_data):
|
|
||||||
tbd_stat = json_data['tbdtime']
|
|
||||||
hold_stat = json_data['inhold']
|
|
||||||
go_stat = json_data['status']
|
|
||||||
if tbd_stat == 1:
|
|
||||||
status = "TBD"
|
|
||||||
elif hold_stat == 1:
|
|
||||||
status = "HOLD"
|
|
||||||
elif go_stat == 1:
|
|
||||||
status = "GO"
|
|
||||||
else:
|
|
||||||
status = "UNKNOWN"
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
class DeltaTemplate(Template):
|
class DeltaTemplate(Template):
|
||||||
delimiter = "%"
|
delimiter = "%"
|
||||||
@ -86,18 +59,10 @@ def next_launch():
|
|||||||
json_data = l.api_request()
|
json_data = l.api_request()
|
||||||
rocket = l.rocket_name(json_data)
|
rocket = l.rocket_name(json_data)
|
||||||
mission = l.mission_name(json_data)
|
mission = l.mission_name(json_data)
|
||||||
status = l.get_status(json_data)
|
launch_time = l.net_raw_utc(json_data)
|
||||||
if status != "GO":
|
now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
|
||||||
deltastring = l.net(json_data)
|
timedelta = abs(launch_time - now)
|
||||||
else:
|
t_string = "-" if launch_time > now else "+"
|
||||||
launch_time = l.net_raw_utc(json_data)
|
deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S")
|
||||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
|
||||||
if launch_time > now:
|
|
||||||
timedelta = launch_time - now
|
|
||||||
t_string = "-"
|
|
||||||
else:
|
|
||||||
timedelta = now - launch_time
|
|
||||||
t_string = "+"
|
|
||||||
deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S")
|
|
||||||
del l
|
del l
|
||||||
return rocket, mission, status, deltastring
|
return rocket, mission, deltastring
|
||||||
|
26
nslookup.py
26
nslookup.py
@ -2,30 +2,30 @@
|
|||||||
|
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
def nslookup(domain, typ="A"):
|
def nslookup(domain, types=["AAAA", "A"]):
|
||||||
result = ""
|
result = ""
|
||||||
rcount = 0
|
rcount = 0
|
||||||
try:
|
try:
|
||||||
answer = dns.resolver.query(domain, typ)
|
for typ in types:
|
||||||
for rdata in answer:
|
answer = dns.resolver.resolve(domain, typ)
|
||||||
if rcount > 0:
|
for rdata in answer:
|
||||||
result += "\n"
|
if rcount > 0:
|
||||||
if hasattr(rdata, 'exchange'):
|
result += "\n"
|
||||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
if hasattr(rdata, 'exchange'):
|
||||||
rcount += 1
|
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||||
else:
|
rcount += 1
|
||||||
result += str(rdata)
|
else:
|
||||||
rcount += 1
|
result += str(rdata)
|
||||||
|
rcount += 1
|
||||||
except dns.resolver.NXDOMAIN as err:
|
except dns.resolver.NXDOMAIN as err:
|
||||||
result = str(err)
|
result = str(err)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
result = "Error"
|
result = "Error"
|
||||||
print("nslookup error! - "+str(err))
|
print("nslookup error! - "+str(err))
|
||||||
del answer
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(nslookup("elmo.space", "AAAA"))
|
print(nslookup("elmo.space"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pytz
|
||||||
|
beautifulsoup4~=4.11
|
||||||
|
dnspython~=2.2
|
||||||
|
feedparser~=6.0
|
||||||
|
requests~=2.0
|
5
rss.py
5
rss.py
@ -3,16 +3,11 @@
|
|||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
import time
|
import time
|
||||||
from subprocess import check_output
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
feed_name = 'fefe'
|
feed_name = 'fefe'
|
||||||
url = 'https://blog.fefe.de/rss.xml'
|
url = 'https://blog.fefe.de/rss.xml'
|
||||||
|
|
||||||
#feed_name = sys.argv[1]
|
|
||||||
#url = sys.argv[2]
|
|
||||||
|
|
||||||
db = 'rss_feeds.db'
|
db = 'rss_feeds.db'
|
||||||
limit = 12 * 3600 * 1000
|
limit = 12 * 3600 * 1000
|
||||||
|
|
||||||
|
1
tweepy
1
tweepy
Submodule tweepy deleted from 2efe385fc6
31
urlinfo.py
31
urlinfo.py
@ -1,31 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import re
|
|
||||||
import requests
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
|
|
||||||
def is_url(msg):
|
|
||||||
regex = r"(https?:\/\/(?:www\.)?\S+)"
|
|
||||||
match = re.search(regex, msg)
|
|
||||||
if match:
|
|
||||||
url = match.group(1)
|
|
||||||
return url
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_data(url):
|
|
||||||
r = requests.get(url)
|
|
||||||
data = r.text
|
|
||||||
r.close()
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def get_title(url):
|
|
||||||
data = get_data(url)
|
|
||||||
soup = BeautifulSoup(data, 'html.parser')
|
|
||||||
title = soup.title.string
|
|
||||||
del soup
|
|
||||||
return title
|
|
||||||
|
|
Reference in New Issue
Block a user