Easier to post here than stackoverflow I want to have 2 python programs, one reads from telegram chat, and the other "pushes" that information to the other program which then analyses it periodically (checks price)
How should they communicate? Since I often reset the scripts and modify it might be cool to have some kind of storage, so I though maybe a text file between them.
Py1 writes to "STACK.txt", Py2 gets a trigger if the STACK file was moddified, reads it and ads it to it's own stack2.txt, and deletes the contents of STACK.txt.
STACK.txt would be opened as write only, so when py1 has a new payload, it would just write at the begining of the file again
you can either have them chat over an HTTP api (see flask) or you can have them leave messages to each other on the file system and you'd have to poll a file every so often (pretty dumb)
if you only need one way messaging you can just have the python script run a command on the operating system "script2.py"
Have the scraper program write to a named pipe that the analysis program reads from. You can either create the pipe in bash, or python, then read from or write to it with whatever # Scraper res = telegrambot.get('blahlblahblah") with open(pipe_name, 'w') as file: file.write(res)
# Analysis program with open(pipe_name) as file: for line in file: analyze(line)
Don't do anything like `while True` to constantly read the pipe or sleep or anything else, both are dumb. Just open it like a regular file and treat it like an iterator. it'll just werk.
Justin Long
forgot to add, `os.mkfifo` is the python function to create the pipe, in bash it's mkfifo. Just check the man page, it's pretty easy to figure out
Jason Murphy
Wow, a solution this simple exists and there were anons actually suggesting writing an entire HTTP fucking API or using a full-blown messaging queuing system like RabbitMQ to do this. Nu-Any Forums truly sucks.
Owen King
I had to figure this out a year or so back when I needed to glue two programs together. API / task runner / long polling / redis etc were my first thought too, but turns out that unix tools are pretty nice and easy to use.