Skip to content

Instantly share code, notes, and snippets.

@brianly
Created November 1, 2013 01:09
Show Gist options
  • Save brianly/7259684 to your computer and use it in GitHub Desktop.
Save brianly/7259684 to your computer and use it in GitHub Desktop.
A version of the data export script that doesn't do certificate checking.
@ECHO OFF
IF [%1]==[] (
IF [%2]==[] (
ECHO "Usage: export.cmd <OAuth Access Token> <Directory>"
EXIT /B
)
)
:: Your Yammer OAuth 2 Access Token. This must be a token for a verified admin account.
SET AT=%1
:: Download location for the export files.
SET DIR=%2
cd %DIR%
:: Find the last export if there is one. The start date and time of the previous export
:: is encoded in the filename
SET LAST_EXPORT=0
IF EXIST export-*.zip (
FOR /f "delims=" %%a in ('dir /B /D export-*.zip') do (
:: Use the timestamp from the most recent file
SET LAST_EXPORT=%%a
)
)
:: Remove the relevant parts of the filename so the timestamp can be stored
SET LAST_EXPORT=%LAST_EXPORT:export-=%
SET LAST_EXPORT=%LAST_EXPORT:.zip=%
:: Don't forget to replace underscores with colons to ensure correct ISO-8601 formatting
SET LAST_EXPORT=%LAST_EXPORT:_=:%
:: Calculate the current date in UNIX time for the filename of the export.
SET TIME_STAMP=%time:~0,2%:%time:~3,2%:%time:~6,2%Z
SET NEXT_EXPORT=%date:~10,4%-%date:~4,2%-%date:~7,2%T%TIME_STAMP%
:: Make sure to replace ":" with "_" so that Windows will save the file
SET NEXT_EXPORT=%NEXT_EXPORT::=_%
:: Make sure to replace any spaces with 0's. DOS doesn't always provide leading 0's
:: when a time fragment is less than 10
SET NEXT_EXPORT=%NEXT_EXPORT: =0%
:: Perform the next export. Send the OAuth 2 access token and store the time of this
:: export in the filename.
SET FILE_NAME=export-%NEXT_EXPORT%.zip
SET AUTH_HEADER=Authorization: Bearer %AT%
SET API_URL=https://www.yammer.com/api/v1/export
ECHO LAST EXPORT %LAST_EXPORT%
wget -O %FILE_NAME% -t 1 --header "%AUTH_HEADER%" --quiet --no-check-certificate %API_URL%?since=%LAST_EXPORT%
echo FILE_NAME %FILE_NAME%
echo AUTH_HEADER %AUTH_HEADER%
echo API_URL %API_URL%
echo LAST_EXPORT %LAST_EXPORT%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment