Skip to content

Instantly share code, notes, and snippets.

@wildekek
Last active April 25, 2016 11:37
Show Gist options
  • Save wildekek/0e7022bc85435917f352dda1169cc3d3 to your computer and use it in GitHub Desktop.
Save wildekek/0e7022bc85435917f352dda1169cc3d3 to your computer and use it in GitHub Desktop.
Grep ADB intents
#!/usr/bin/python
import re
import datetime
from pyadb import ADB
adb = ADB('/Users/willem/Library/Android/sdk/platform-tools/adb')
adb.shell_command('dumpsys alarm')
batchMatch = re.search(r'Pending alarm batches: [0-9]+[\n\r]+(.*}})[\n\r]+', adb.get_output(), re.M|re.S)
if batchMatch:
#print batchMatch.group(1)
batches = re.split(r'\nBatch{', batchMatch.group(1))
for batch in batches:
eventsMatch = re.search(r'(\w+).*}:[\n\r]+\s+(.*)', batch, re.M|re.S)
batchID = eventsMatch.group(1)
events = re.split(r'}}[\n\r]+\s+', eventsMatch.group(2))
for event in events:
eventMatch = re.search(r'(\w+) .*when ([0-9]+) ([\w\.]+)}.*', event, re.M|re.S)
eventType = eventMatch.group(1)
eventTime = eventMatch.group(2)
eventProduct = eventMatch.group(3)
if eventProduct == "com.alarmclock.xtreme.free":
print batchID
print eventMatch.group()
#date = datetime.fromtimestamp(eventTime / 1e3)
#print(
# datetime.datetime.fromtimestamp(
# int("1284101485")
# ).strftime('%Y-%m-%d %H:%M:%S')
#)
print "\n\n"
else:
print "No match!!"
#Alarm Stats:
#entries = re.split("\n+", text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment