Jan-04-2020, 05:09 PM
Hey there,
I've been working on my code, a bit, and i want to make it work more efficient.
I want to make a program that sends a random photo from a certain folder to a certain user every X hours/days.
User ids, folders and frequency may vary. I want to make a scalable solution to make it easy to add new users.
I want to make a function that can be called easily which has all the arguments (folder_name, user_id, frequency). I know the attached code is not working properly, but this is where i got stuck.
Help is much appreciated.
mesaj_fb (folder_name, user_id, frequency) - and to be able to call it easily in the main function everytime i want to add a new user. I don't want to add 10 new lines of code everytime i add a new user.
I've been working on my code, a bit, and i want to make it work more efficient.
I want to make a program that sends a random photo from a certain folder to a certain user every X hours/days.
User ids, folders and frequency may vary. I want to make a scalable solution to make it easy to add new users.
I want to make a function that can be called easily which has all the arguments (folder_name, user_id, frequency). I know the attached code is not working properly, but this is where i got stuck.
Help is much appreciated.
import fbchat from fbchat.models import * import random,os from apscheduler.schedulers.blocking import BlockingScheduler import docs import lista_prieteni client = fbchat.Client(docs.username, docs.password) friend = client.searchForUsers(lista_prieteni.lista) id1 = friend[0].uid path1 = r"D:\Downloads\poze test\masini" def mesaj_fb(path,id): random_filename = random.choice([ x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))]) print(random_filename) client.sendLocalImage(os.path.join(path, random_filename),message=Message(text="Doza ta zilnica de..."),thread_id=id) def main(): sched = BlockingScheduler() sched.add_job(mesaj_fb(path1,id1), 'interval', minutes=10) sched.start() main()i would like to create a function that looks like :
mesaj_fb (folder_name, user_id, frequency) - and to be able to call it easily in the main function everytime i want to add a new user. I don't want to add 10 new lines of code everytime i add a new user.