Skip to content
This repository was archived by the owner on Jan 19, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ The files in the `stat` folder are self-explanatory; they allow for learning int

Log into [GroupMe's web interface](https://web.groupme.com/groups) and use Chrome or Safari's inspector to monitor the network requests when you load one of your groups.

You'll notice a GET request to an endpoint `https://v2.groupme.com/groups/GROUP_ID/messages`.
You'll notice a GET request to an endpoint `https://v2.groupme.com/groups/GROUP_ID/messages` for a group chat, or `https://api.groupme.com/v3/direct_messages?other_user_id=OTHER_USER_ID` for direct messages.

One of the headers sent with that request, `X-Access-Token`, is your access token.

## Finding your group ID

Again, in GroupMe's web interface, the group ID is the numeric ID included in the group's URL (`https://web.groupme.com/groups/GROUP_ID`).
Again, in GroupMe's web interface, the group ID is the numeric ID included in the group's URL (`https://web.groupme.com/groups/GROUP_ID`). For direct messages, you'll need the other_user_id.

## Requirements/Dependencies/Python

Expand Down
13 changes: 9 additions & 4 deletions groupme-fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ def main():
specific message IDs
"""
parser = argparse.ArgumentParser()
parser.add_argument('group')
parser.add_argument('group', help="The group id (for group chats) or other_user_id (for direct messages) from your GroupMe Web session")
parser.add_argument('accessToken')
parser.add_argument("--resumePrevious", action='store_true', default=False, help="Resume based on the last found files and get previous messages.")
parser.add_argument("--resumeNext", action='store_true', default=False, help="Resume based on the last found files and get next messages.")
parser.add_argument("--oldest", help="The ID of the oldest (topmost) message in the existing transcript file")
parser.add_argument("--newest", help="The ID of the newest (bottom-most) message in the existing transcript file")
parser.add_argument("--pages", type=int,
help="The number of pages to pull down (defaults to as many as the conversation has")
parser.add_argument("--mode", default="group", help="Type of chat to download: 'group' or 'direct_messages'. Defaults to group.")

args = parser.parse_args()

Expand All @@ -50,6 +51,7 @@ def main():
beforeId = args.oldest
stopId = args.newest
pages = args.pages
mode = args.mode

transcriptFileName = 'transcript-{0}.json'.format(group)
transcript = loadTranscript(transcriptFileName)
Expand All @@ -64,7 +66,7 @@ def main():
else:
stopId = transcript[-1]['id']

transcript = populateTranscript(group, accessToken, transcript, beforeId, stopId, pages)
transcript = populateTranscript(group, accessToken, transcript, beforeId, stopId, mode, pages)

# sort transcript in chronological order
transcript = sorted(transcript, key=lambda k: k[u'created_at'])
Expand Down Expand Up @@ -120,10 +122,13 @@ def loadTempTranscript(tempFileName):
return []


def populateTranscript(group, accessToken, transcript, beforeId, stopId, pageLimit=None):
def populateTranscript(group, accessToken, transcript, beforeId, stopId, mode, pageLimit=None):
complete = False
pageCount = 0
endpoint = 'https://v2.groupme.com/groups/' + group + '/messages'
if mode == 'direct_messages':
endpoint = 'https://api.groupme.com/v3/direct_messages?other_user_id=' + group
else:
endpoint = 'https://v2.groupme.com/groups/' + group + '/messages'
headers = {
'Accept': 'application/json, text/javascript',
'Accept-Charset': 'ISO-8859-1,utf-8',
Expand Down
16 changes: 12 additions & 4 deletions html-transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ def write_html_transcript(messages, outfile, imgcache):
text = message[u'text']
if text is None:
text = u''
system = message[u'system']
system = message.get(u'system', None)
faves = message[u'favorited_by']
nlikes = faves if faves == 0 else len(faves)
pic = message[u'picture_url']
pic = message.get(u'picture_url', None)

# Picture is included as an attachment on direct messages.
# This might have to be rewritten if there are ever multiple images
# attached to a single message. Right now I've only seen multiple
# attachments for emoji.
if message.get(u'attachments', []) != []:
if message[u'attachments'][0].get(u'type', None) in ['image', 'linked_image']:
pic = message[u'attachments'][0][u'url']


# Open div
Expand Down Expand Up @@ -122,8 +130,8 @@ def write_html_transcript(messages, outfile, imgcache):
def write_html(folder, messages, emoji=True):
imgcache = ImageCache(folder)
index_fn = os.path.join(folder, 'index.html')
shutil.copyfile('assets/groupme.css', os.path.join(folder, 'groupme.css'))
shutil.copyfile('assets/groupme.js', os.path.join(folder, 'groupme.js'))
shutil.copyfile(sys.path[0] + '/assets/groupme.css', os.path.join(folder, 'groupme.css'))
shutil.copyfile(sys.path[0] + '/assets/groupme.js', os.path.join(folder, 'groupme.js'))
with open(index_fn, 'w') as f:
f.write(_HTML_HEADER)
write_html_transcript(messages, f, imgcache)
Expand Down
10 changes: 6 additions & 4 deletions simple-transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def printTranscript(messages, outputFilename):
else:
text = "(no text)"

if message[u'system'] is True:
if message.get(u'system', None) is True:
system_padded = '(SYS) '
else:
system_padded = ''
Expand All @@ -31,10 +31,12 @@ def printTranscript(messages, outputFilename):
else:
favorites_padded = ''

if message[u'picture_url'] is not None:
pic = ''
if message.get(u'picture_url') is not None:
pic = ' ; photo URL ' + message[u'picture_url']
else:
pic = ''
elif message.get(u'attachments', []) != []:
if message[u'attachments'][0].get(u'type', None) in ['image', 'linked_image']:
pic = ' ; photo URL ' + message[u'attachments'][0][u'url']

line = u'{0}{1}({2}){3}: {4}{5}\n'.format(
system_padded, name, time, favorites_padded, text, pic
Expand Down