Convert some data
names = ‘peter, alex; andrea, florin, mihai’ (Don’t change string format)
– Convert string to a list
– Generate for list with 25 datalines. One name per line. Then a space. A random number to the end containing 3 digits. Exemple: alex 327 (new line) peter 252
– Sum up all 3 digits from all 25 lines above (the medium of the random number should be 12500)
– If the number is higher than 12500 print out “Higher than 12500 (number)” else “Lower than 12500 (number)”. Also show an error if they are not digits.
Write a Function to get data from file and resave
Create a file named nameage.json with content {‘peter’ => ’25’, ‘alex’: ’22’, ‘name3′:’42’}
– Get data from file
– Convert them to:
peter, 25
alex, 22
andrea, 42
– Resave this it in a file named nameage.txt (one per line like in the exemple above)
Check if to run
# That Function is used to run another function a limited number of times per day, split equally during the day
# Script to code should be written in Python
# A cron runs the function you have to code every 5 minutes
# It should Print out “Run now” when all conditions match. That means if (at the time calling the function) it is in time interval (intervalfrom and intervalto; representing daytime hours), within limits (runs_per_day) and split during that day equally.
# That means not just run once every 5min until runs_per_day is equal to runs_counter. In the example below, first should run between 10-12 o clock, second between 12-14…
# Example conditions resulting in “Run now”: function is being called, run_counter = 2 and hournow between 14 – 16 o’clock.
# If somehow something else ran between an interval (means the run_counter was not updated) it should run anyway on the next interval
# intervals from to, runs_per_day can of course change like: runs_per_day = 7, intervalfrom = 3, intervalto = 14
Variables:
from time import localtime, strftime
run_counter = 2 # That increments when run. Use update_run_counter() for updating
runs_per_day = 5
intervalfrom = 10
intervalto = 20
hournow = strftime(“%H”, localtime()) # Change time to check
Create a Function named download_file(url)
– downloads a file and return the path where it was saved localy.
– download: http://www.africau.edu/images/default/sample.pdf
– the downloaded file is named after the name on the server with its extensions (sample.pdf)