-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated more of getting locale files from Twitter
- Loading branch information
Showing
10 changed files
with
37 additions
and
110 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
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
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,11 +1,17 @@ | ||
## Updating Locales | ||
|
||
Tweak `html/_files.txt` if needed to add new locales. | ||
### Get locale files from Twitter | ||
|
||
In `html/` run `curl -K _files.txt` to retrieve HTML from Twitter with the latest URLs for hashed locale files. | ||
> Tweak `html/_files.txt` and `create-js-curl-config.js` first if locales have changed. | ||
Use the contents of the HTML files to update `js/_files.txt` - left as an exercise for the reader. | ||
```sh | ||
(cd html && curl -K _files.txt) | ||
node create-js-curl-config.js | ||
(cd js && curl -K _files.txt) | ||
``` | ||
|
||
In `js/` run `curl -K _files.txt` to retrieve locale files. | ||
### Create locale object for tweak-new-twitter.user.js | ||
|
||
Run `node create-locales.js` to create a `locales.js` file and use it to update `tweak-new-twitter.user.js`. | ||
Run `node create-locales.js` to create `locales.js`. | ||
|
||
Open it, save to format it with Prettier, then use its contents to update `tweak-new-twitter.user.js`. |
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,23 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
let curlConfig = '' | ||
for (let file of fs.readdirSync('./html')) { | ||
if (!file.endsWith('.html')) continue | ||
let localeCode = file.split('.')[0] | ||
let html = fs.readFileSync(path.join('html', file), {encoding: 'utf8'}) | ||
let match = html.match( | ||
new RegExp( | ||
`https://abs\\.twimg\\.com/responsive-web/client-web-legacy/i18n/${localeCode}\\.(?:[a-z\\d]+)\\.js` | ||
) | ||
) | ||
|
||
if (!match) { | ||
console.log('could not find locale file URL', {file, localeCode}) | ||
continue | ||
} | ||
|
||
curlConfig += `-o ${localeCode}.js\nurl="${match[0]}"\n` | ||
} | ||
|
||
fs.writeFileSync('./js/_files.txt', curlConfig) |
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
Empty file.
This file was deleted.
Oops, something went wrong.
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