Created
February 11, 2024 11:08
-
-
Save josifoski/044d8360211dddf86a2c277ce17f1225 to your computer and use it in GitHub Desktop.
twitalert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
import re | |
import codecs | |
import sys | |
import time | |
import os | |
import tkinter | |
from tkinter import messagebox | |
import platform | |
if platform.system() == "Windows": | |
import winsound | |
# INPUT | |
#twituser = 'josifsk' #put username here | |
twituser = 'tarynsouthern' | |
whichlist = 'mypvt' #put your list here | |
# twitalert.py for alerting with notification for new tweets on twitter list | |
# it depends on installed wonderful twitter console application https://github.com/sferik/t | |
# by Aleksandar Josifoski http://twitter.com/josifsk | |
# Please set sound file for alarm bellow in line 63 | |
# script can be started with: python3 twitalert.py | |
def strip_nasty_characters(input): | |
if input: | |
try: | |
# Wide UCS-4 build | |
myre = re.compile(u'[' | |
u'\U0001F300-\U0001F64F' | |
u'\U0001F680-\U0001F6FF' | |
u'\u2600-\u26FF\u2700-\u27BF]+', | |
re.UNICODE) | |
except re.error: | |
# Narrow UCS-2 build | |
myre = re.compile(u'(' | |
u'\ud83c[\udf00-\udfff]|' | |
u'\ud83d[\udc00-\ude4f\ude80-\udeff]|' | |
u'[\u2600-\u26FF\u2700-\u27BF])+', | |
re.UNICODE) | |
input = re.sub(myre, "", input) | |
return input | |
i = 0 | |
time.sleep(11) #change to greater number for example 33 (that is seconds) if you put script in your startup programs. How? google it, or use Linux. | |
while True: | |
if not os.path.isfile('twitalerthistory.txt'): | |
history = codecs.open('twitalerthistory.txt', 'w', 'utf-8') | |
history.close() | |
history = codecs.open('twitalerthistory.txt', 'r', 'utf-8') | |
h = history.read() | |
history.close() | |
#os.system("t list timeline -l -r -n 15 %s/%s > temp.txt" % (twituser, whichlist)) | |
os.system("t timeline -l -r -n 15 %s > temp.txt" % (twituser)) | |
ftemp = codecs.open('temp.txt', 'r', 'utf-8') | |
stemp = ftemp.read() | |
ftemp.close() | |
os.remove('temp.txt') | |
lstemp = stemp.split('\n') | |
del lstemp[-1] | |
success = [] | |
for twit in lstemp: | |
if not twit.split()[0] in h: | |
success.append(twit) | |
history = codecs.open('twitalerthistory.txt', 'a', 'utf-8') | |
for twit in success: | |
history.write(twit + ' |' + whichlist + '\n') | |
history.close() | |
if len(success) > 0: | |
try: | |
soundfile = '/data/music24/Evergrini/Stand_by_me.mp3' # <- put soundfile in same directory with script and enter it's name here, use wav file | |
if platform.system() == "Linux": | |
#os.system("mpv %s" % soundfile.strip()) | |
pass | |
if platform.system() == "Windows": | |
#winsound.PlaySound(soundfile.strip(), winsound.SND_FILENAME) | |
except Exception as a: | |
print(str(a)) | |
root = tkinter.Tk() | |
root.withdraw() | |
sout = '' | |
for item in success: | |
sout += ' '.join(item.split()[1:]) + '\n\n' | |
sout = strip_nasty_characters(sout) | |
messagebox.showinfo("twitalert", sout) | |
root.destroy() | |
i += 1 | |
print(str(i) + ': twit alert working in background...') | |
time.sleep(120) #recheck on every 2 min |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment