1

I want to make this script to run automatically once or twice a day at a specified time, what would be the best way to approach this.

def get_data():
    """Reads the currency rates from cinkciarz.pl and prints out, stores the pln/usd
       rate in a variable myRate"""

    sock = urllib.urlopen("https://cinkciarz.pl/kantor/kursy-walut-cinkciarz-pl/usd") 
    htmlSource = sock.read()                            
    sock.close()                                        

    currancyRate = re.findall(r'<td class="cur_down">(.*?)</td>',str(htmlSource))

    for eachTd in currancyRate:
        print(eachTd)

    print currancyRate[0]
    myRate = currancyRate[0]
    print myRate
    return myRate
leela.fry
  • 283
  • 2
  • 3
  • 13

2 Answers2

1

You can use crontab to run any script at regular intervals. See https://stackoverflow.com/a/8727991/1517864

To run a script once a day (at 12:00) you will need an entry like this in your crontab

0 12 * * * python /path/to/script.py
Community
  • 1
  • 1
jayant
  • 2,349
  • 1
  • 19
  • 27
0

You can add a bash function.

while true; do <your_command>; sleep <interval_in_seconds>; done
Anekdotin
  • 1,531
  • 4
  • 21
  • 43