Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- import math
- import datetime
- import calendar
- import android
- latitude = math.radians(99.999)
- longitude = math.radians(-99.999)
- # geo-fence in feet
- radius = 5000
- def in_geo_fence(la, lo):
- # radius of earth in feet
- R = 209255259
- distance = math.acos(math.sin(latitude) * math.sin(la) + math.cos(latitude) * math.cos(la) * math.cos(lo - longitude)) * R
- return distance < radius
- MONDAY = 0
- FRIDAY = 4
- now = datetime.datetime.now()
- weekday = now.weekday()
- day = now.day
- last_day = calendar.monthrange(now.year, now.month)[1]
- # it is payday if:
- # today is the 15th and Monday - Friday or
- # today is the 14th and Friday or
- # today is the 16th and Monday or
- # today is the last day of month and Monday - Friday or
- # tomorrow is last day of month and today is Friday or
- # today is the 1st day of month and Monday
- # for testing
- day = 15
- weekday = FRIDAY
- payday = (day == 15 and weekday <= FRIDAY) \
- or (day == 14 and weekday == FRIDAY) \
- or (day == 16 and weekday == MONDAY) \
- or (day == last_day and weekday <= FRIDAY) \
- or (day + 1 == last_day and weekday == FRIDAY) \
- or (day == 1 and weekday == MONDAY)
- if not payday:
- sys.exit()
- #android.makeToast('payday!')
- hour = now.hour
- minute = now.minute
- # for testing
- hour = 15
- minute = 30
- late_afternoon = (hour >= 15 and minute >= 30) and (hour <= 18 and minute <= 30)
- if not late_afternoon:
- sys.exit()
- #android.makeToast('late afternoon!')
- android = android.Android()
- android.startLocating()
- time.sleep(5)
- loc = android.readLocation().result
- if loc == {}:
- loc = android.getLastKnownLocation().result
- android.stopLocating()
- if loc != {}:
- try:
- n = loc['gps']
- except KeyError:
- n = loc['network']
- la = math.radians(n['latitude'])
- lo = math.radians(n['longitude'])
- # for testing
- la = latitude
- lo = longitude
- if in_geo_fence(la, lo):
- # how to make notification sound?
- android.notify('Deposit Check', '')
Add Comment
Please, Sign In to add comment