Skip to content

Instantly share code, notes, and snippets.

@mertbozkir
Created August 19, 2025 08:45
Show Gist options
  • Save mertbozkir/2cd49940616e429bafda85448fdbc280 to your computer and use it in GitHub Desktop.
Save mertbozkir/2cd49940616e429bafda85448fdbc280 to your computer and use it in GitHub Desktop.
60hr workweek
// Discord webhook URL
const DISCORD_WEBHOOK = "Your github hook.";
function sendDiscordMessage(message) {
const payload = JSON.stringify({content: message});
const params = {
headers: {"Content-Type": "application/json"},
method: "POST",
payload: payload,
muteHttpExceptions: true
};
try {
const response = UrlFetchApp.fetch(DISCORD_WEBHOOK, params);
console.log('Discord message sent:', response.getContentText());
} catch (error) {
console.error('Error sending Discord message:', error.toString());
}
}
function createDailyReport() {
// Get today's date in format: "thu, 19 aug"
const today = new Date();
const dayNames = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
const monthNames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
const dayName = dayNames[today.getDay()];
const dayNum = today.getDate();
const monthName = monthNames[today.getMonth()];
const formattedDate = `${dayName}, ${dayNum} ${monthName}`;
try {
// Find your template document by name
const templateFiles = DriveApp.getFilesByName('60hr-workweek-template');
if (!templateFiles.hasNext()) {
throw new Error('Template document "60hr-workweek-template" not found!');
}
const templateFile = templateFiles.next();
// Create a copy of the template
const newFileName = `${formattedDate}`;
const newFile = templateFile.makeCopy(newFileName);
// Open the new document and replace {{date}} placeholder
const newDoc = DocumentApp.openById(newFile.getId());
const body = newDoc.getBody();
// Replace {{date}} with actual date
body.replaceText('{{date}}', formattedDate);
// Save the document
newDoc.saveAndClose();
// Send Discord notification with clickable link
const docUrl = newFile.getUrl();
const discordMessage = `Daily report for [**${formattedDate}**](${docUrl}) is ready! --- *60hr workweek experiment*`;
sendDiscordMessage(discordMessage);
// Log success (you can see this in Apps Script logs)
console.log(`Created daily report: ${newFileName}`);
console.log(`Document URL: https://docs.google.com/document/d/${newFile.getId()}/edit`);
return newFile.getUrl();
} catch (error) {
console.error('Error creating daily report:', error.toString());
throw error;
}
}
// Optional: Function to set up daily trigger (run this once to set up automation)
function setupDailyTrigger() {
// Delete existing triggers for this function
const triggers = ScriptApp.getProjectTriggers();
triggers.forEach(trigger => {
if (trigger.getHandlerFunction() === 'createDailyReport') {
ScriptApp.deleteTrigger(trigger);
}
});
// Create new daily trigger (runs at 8 AM every day)
ScriptApp.newTrigger('createDailyReport')
.timeBased()
.everyDays(1)
.atHour(7) // Change this to your preferred hour (0-23)
.create();
console.log('Daily trigger set up successfully! Will run at 7 AM every day.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment