Guest User

Untitled

a guest
Oct 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import sys
  2. import time
  3. import math
  4. import datetime
  5. import calendar
  6. import android
  7.  
  8. latitude = math.radians(99.999)
  9. longitude = math.radians(-99.999)
  10. # geo-fence in feet
  11. radius = 5000
  12.  
  13. def in_geo_fence(la, lo):
  14.     # radius of earth in feet
  15.     R = 209255259
  16.     distance = math.acos(math.sin(latitude) * math.sin(la) + math.cos(latitude) * math.cos(la) * math.cos(lo - longitude)) * R
  17.     return distance < radius
  18.  
  19. MONDAY = 0
  20. FRIDAY = 4
  21. now = datetime.datetime.now()
  22. weekday = now.weekday()
  23. day = now.day
  24. last_day =  calendar.monthrange(now.year, now.month)[1]
  25.  
  26. # it is payday if:
  27. # today is the 15th and Monday - Friday or
  28. # today is the 14th and Friday or
  29. # today is the 16th and Monday or
  30. # today is the last day of month and Monday - Friday or
  31. # tomorrow is last day of month and today is Friday or
  32. # today is the 1st day of month and Monday
  33.  
  34. # for testing
  35. day = 15
  36. weekday = FRIDAY
  37.  
  38. payday = (day == 15 and weekday <= FRIDAY) \
  39.     or (day == 14 and weekday == FRIDAY) \
  40.     or (day == 16 and weekday == MONDAY) \
  41.     or (day == last_day and weekday <= FRIDAY) \
  42.     or (day + 1 == last_day and weekday == FRIDAY) \
  43.     or (day == 1 and weekday == MONDAY)
  44. if not payday:
  45.     sys.exit()
  46.  
  47. #android.makeToast('payday!')
  48.  
  49. hour = now.hour
  50. minute = now.minute
  51. # for testing
  52. hour = 15
  53. minute = 30
  54.  
  55. late_afternoon = (hour >= 15 and minute >= 30) and (hour <= 18 and minute <= 30)
  56. if not late_afternoon:
  57.     sys.exit()
  58.  
  59. #android.makeToast('late afternoon!')
  60.  
  61. android = android.Android()
  62. android.startLocating()
  63. time.sleep(5)
  64. loc = android.readLocation().result
  65. if loc == {}:
  66.     loc = android.getLastKnownLocation().result
  67. android.stopLocating()
  68. if loc != {}:
  69.     try:
  70.         n = loc['gps']
  71.     except KeyError:
  72.         n = loc['network']
  73.     la = math.radians(n['latitude'])
  74.     lo = math.radians(n['longitude'])
  75.  
  76.     # for testing
  77.     la = latitude
  78.     lo = longitude
  79.     if in_geo_fence(la, lo):
  80.         # how to make notification sound?
  81.         android.notify('Deposit Check', '')
Add Comment
Please, Sign In to add comment