Python Forum
Creating multiple text fies from new url retrieve results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating multiple text fies from new url retrieve results
#1
Hi,

This is a similar question to what I posted earlier, however I've made some improvements and my function is (almost) doing what I want it to do. This code below is opening the same url that contains different data every time it opens, every 3 seconds and retrieving the text from it. However, every time the URL opens I would like a separate text file for the results, right now it updates the "testing.txt" file and saves the latest result from when I close exit the function.

I'd like a separate file for each 3 second interval, but if all results are stored into one master text file that works for me as well. Any and all help is welcome, thank you!!

import webbrowser
import schedule
import time
import urllib


def job():
    webbrowser.open('http://127.0.0.1:56781/mavlink/')

    urllib.urlretrieve('http://127.0.0.1:56781/mavlink/', "testing.txt")
    

schedule.every(3).seconds.do(job)

while 1:
    schedule.run_pending()
    time.sleep(1)
Reply
#2
The following is a modified example from the APScheduler that should do the trick.
I have not tested it, so you may find a bug or two
the scheduler can be downloaded with:
pip install APScheduler
code:
"""
This code is a modified version of the tornado scheduler from the APScheduler package examples
"""
import os

from tornado.ioloop import IOLoop
from apscheduler.schedulers.tornado import TornadoScheduler

COUNT = 1

def job():
    webbrowser.open('http://127.0.0.1:56781/mavlink/')
    filename = 'testing{}.txt'.format(COUNT)
    COUNT += 1
    urllib.urlretrieve('http://127.0.0.1:56781/mavlink/', filename)


if __name__ == '__main__':
    scheduler = TornadoScheduler()
    scheduler.add_job(job, 'interval', seconds=3)
    scheduler.start()
    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

    # Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
    try:
        IOLoop.instance().start()
    except (KeyboardInterrupt, SystemExit):
        pass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo put a green boarder and text around multiple pictures jackosullivan 5 1,488 Jul-05-2022, 10:39 AM
Last Post: snippsat
Question Pandas : How to create an algorithm that helps me improve results and creating new co Smordy 8 2,271 Apr-10-2022, 10:28 PM
Last Post: Larz60+
  [Answered] Retrieve a set of rows from text file knob 4 1,802 Dec-22-2021, 07:45 PM
Last Post: knob
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,168 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Open and read multiple text files and match words kozaizsvemira 3 6,771 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Reading Multiple text Files in pyhton Fatim 1 1,942 Jun-25-2021, 01:37 PM
Last Post: deanhystad
Question How to extract multiple text from a string? chatguy 2 2,392 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  Writing unit test results into a text file ateestructural 3 4,775 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  cx_Oracle.DatabaseError: Error while trying to retrieve text from error ORA-01804 rajeshparadker 0 8,648 Nov-12-2020, 07:34 PM
Last Post: rajeshparadker
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,245 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020