uploader_1.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. def upload_to_slack(pictures, slack_bot):
  2. """Uploads the pictures to slack and a message depending on request situation.
  3. Checks the temp request file for a request and sends messages depending on,
  4. if there is a request.
  5. If the last request ran out, this person is getting notified.
  6. If not, tell person, trigger has been received.
  7. Upload to slack
  8. """
  9. channel = get_key('Slack', 'channel_name')
  10. request = slack_bot.queue.get()
  11. if request['request']:
  12. if time() <= request['ts']:
  13. message = "Received the trigger in time, you will get the photo!"
  14. channel = request['channel']
  15. else:
  16. # Hmm, this should never happen ... keep it in, just to be sure
  17. message = "Hey, sorry but you missed your request window, but I told you that."
  18. SlackBot.send_ephemeral_message(SlackBot,
  19. msg=message,
  20. user=request['user'],
  21. channel=request['channel'])
  22. # Make sure we pick the right file
  23. SlackBot.upload_file(SlackBot, pictures[0], channel)
  24. send_feedback(Message.UPLOAD)
  25. if get_bool_key('Output', 'enhance'):
  26. SlackBot.upload_file(SlackBot, pictures[1], channel)
  27. if request['request']:
  28. request['request'] = False
  29. request['user'] = None
  30. request['real_name'] = None
  31. request['channel'] = None
  32. request['ts'] = float(get_key('Slack', 'request_period'))
  33. slack_bot.queue.put(request)
  34. print("after slack upload")