-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: fixed ts type of google apps script
- Loading branch information
Showing
5 changed files
with
47 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
14.16.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"arrowParens": "always", | ||
"singleQuote": true | ||
"singleQuote": true, | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,69 @@ | ||
type Headers = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
[key: string]: any | ||
} | ||
|
||
const booklogId: string = PropertiesService.getScriptProperties() | ||
.getProperty('BOOKLOG_ID') | ||
.getProperty('BOOKLOG_ID') || "" | ||
|
||
const booklogPassword: string = PropertiesService.getScriptProperties() | ||
.getProperty('BOOKLOG_PASSWORD') | ||
.getProperty('BOOKLOG_PASSWORD') || "" | ||
|
||
const logSheet: Sheet = SpreadsheetApp.getActiveSpreadsheet() | ||
const logSheet = SpreadsheetApp.getActiveSpreadsheet() | ||
.getSheetByName('log') | ||
|
||
const searchEmail = (): GmailThread[] => { | ||
const searchEmail = () => { | ||
return GmailApp.search("from:[email protected] in:inbox") | ||
} | ||
|
||
const loginToBooklog = (): string[] => { | ||
const url = 'https://booklog.jp/login' | ||
const res = UrlFetchApp.fetch(url, { | ||
const params = { | ||
method: 'post', | ||
followRedirects: false, | ||
headers: { Referer: url }, | ||
payload: { | ||
account: booklogId, | ||
password: booklogPassword | ||
} | ||
}) | ||
|
||
const headers = res.getAllHeaders() | ||
} as GoogleAppsScript.URL_Fetch.URLFetchRequestOptions | ||
const res = UrlFetchApp.fetch(url, params) | ||
|
||
if (typeof headers['Set-Cookie'] === 'undefined') { | ||
return [] | ||
} | ||
const headers = res.getAllHeaders() as Headers | ||
|
||
const cookies = headers['Set-Cookie'] === 'string' | ||
if ('Set-Cookie' in headers) { | ||
const cookies = headers['Set-Cookie'] === 'string' | ||
? [headers['Set-Cookie']] | ||
: headers['Set-Cookie'] | ||
|
||
for (let i = 0; i < cookies.length; i++) { | ||
cookies[i] = cookies[i].split(';')[0] | ||
} | ||
for (let i = 0; i < cookies.length; i++) { | ||
cookies[i] = cookies[i].split(';')[0] | ||
} | ||
|
||
return cookies | ||
return cookies | ||
return [] | ||
} else { | ||
return [] | ||
} | ||
} | ||
|
||
const getAsinList = (thread: GmailThread): string[] => { | ||
const getAsinList = (thread: GoogleAppsScript.Gmail.GmailThread): string[] => { | ||
const asinList = thread.getMessages()[0] | ||
.getBody() | ||
.match(/dp%2F.{10}/g) | ||
|
||
if (!asinList) { | ||
return [] | ||
} | ||
|
||
for (let i = 0; i < asinList.length; i++) { | ||
asinList[i] = asinList[i].slice(-10) | ||
} | ||
|
||
return asinList | ||
} | ||
|
||
const uploadBook = (cookies: string[], asinList: string[]): HTTPResponse => { | ||
const uploadBook = (cookies: string[], asinList: string[]): GoogleAppsScript.URL_Fetch.HTTPResponse => { | ||
const url = 'https://booklog.jp/input' | ||
|
||
return UrlFetchApp.fetch(url, { | ||
|
@@ -70,7 +81,9 @@ const uploadBook = (cookies: string[], asinList: string[]): HTTPResponse => { | |
} | ||
|
||
const log = (asin: string, text: string): void => { | ||
logSheet.appendRow([new Date(), asin, text]) | ||
if (logSheet && text) { | ||
logSheet.appendRow([new Date(), asin, text]) | ||
} | ||
} | ||
|
||
export const main = (): void => { | ||
|
@@ -88,7 +101,7 @@ export const main = (): void => { | |
return | ||
} | ||
|
||
threads.forEach((thread: GmailThread) => { | ||
threads.forEach((thread: GoogleAppsScript.Gmail.GmailThread): void => { | ||
const asinList = getAsinList(thread) | ||
if (typeof asinList !== 'undefined') { | ||
Logger.log('asin is: ' + asinList.join(', ')) | ||
|
@@ -97,9 +110,14 @@ export const main = (): void => { | |
const results = res.getContentText() | ||
.match(/.*tc(?:pink|blue) t10M.*/g) | ||
|
||
results.forEach((result: string) => { | ||
log(asinList.join(', '), result.match(/>(.*)</)[1]) | ||
}) | ||
if (results) { | ||
results.forEach((result: string) => { | ||
const text = result.match(/>(.*)</) | ||
if (text) { | ||
log(asinList.join(', '), text[1]) | ||
} | ||
}) | ||
} | ||
|
||
thread.markRead().moveToArchive() | ||
} else { | ||
|
This file was deleted.
Oops, something went wrong.