twilight
Twitter Streaming API tools and data transformations for Node.js
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.4%) to scientific vocabulary
Repository
Twitter Streaming API tools and data transformations for Node.js
Basic Info
Statistics
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 1
- Releases: 0
Metadata Files
README.md
twilight
Tools for accessing the Twitter API v1.1 with paranoid timeouts and de-pagination.
Node.js
twitter-curlfor querying the streaming API (/sample.jsonand/filter.json).rtcountfor pulling out the retweets from a stream of JSON tweets, and counting them.
Python
json2ttv2converts directories full of Twitter.jsonfiles into.ttv2files, bzip2'ing them, and ensuring that the result is within a reasonable size of the source (greater than 2%, but less than 6%) before deleting the original json.twitter-userpulls down the ~3,200 (max) tweets that are accessible for a given user (also depends on the~/.twitterauth file).
Crawling quickstart
Install from npm:
npm install -g twilight
Or github (to make sure you're getting the most up-to-date version):
npm install -g git://github.com/chbrown/twilight
Authenticate
This app uses only OAuth 1.0A, which is mandatory. As of June 11, 2013, basic HTTP authentication is disabled in the Twitter Streaming API. So get some OAuth credentials together real quick and make a csv file that looks like this:
| consumerkey | consumersecret | accesstoken | accesstoken_secret | |--------------|-----------------|--------------|---------------------| | ziurk0An7... | VKmTsGrk2JjH... | 91505165... | VcLOIzA0mkiCSbU... | | 63Yp9EG4t... | DhrlIQBMUaoL... | 91401882... | XJa4HQKMgqfd7ee... | | ... | ... | ... | ... |
There must be a header line with exactly the following values:
- consumer_key
- consumer_secret
- access_token
- accesstokensecret
Tab / space seperated is fine, and any other columns will simply be ignored, e.g., if you want to record the screen_name of each account. Also, order doesn't matter -- your headers just have to line up with their values.
The twitter-curl script expects to find this file at ~/.twitter,
but you can specify a different path with the --accounts command line argument.
From my /etc/supervisor/conf.d/*
(See http://supervisord.org/ to get that all set up.)
bash
[program:justinnnnnn]
user=chbrown
command=twitter-curl
--filter "track=loveyabiebs,belieber,bietastrophe"
--file /data/twitter/justin_TIMESTAMP.json
--timeout 86400
--interval 3600
--ttv2
twitter-curl options
--accountsshould point to a file with OAuth Twitter account credentials. Currently, the script will simply use a random row from this file.--filtercan be anytrack=whateverorlocations=-18,14,68,44etc. Aquerystring-parsable string. If no filter is specified, it will use the spritzer at/sample.json--fileshouldn't require creating any directions, and the TIMESTAMP bit will be replaced by a filesystem-friendly iso representation of whenever the program is started.
javascript
// Specifically:
var stamp = new Date().toISOString().replace(/:/g, '-').replace(/\..+/, '');
// stamp == '2013-06-07T15-47-49'
--timeout(seconds) the program will die with error code 1 after this amount of time. Don't specify a timeout if you don't want this.--interval(seconds) the amount of time to allow for silence from Twitter before dying. Also exits with code 1. Defaults to 600 (10 minutes).--ttv2(boolean) output TTV2 normalized flat tweets instead of full JSON.
Because in most cases of error the script simply dies, this approach only really makes sense if you're putting it behind some process monitor. (By the way, I've tried most of them: monitd, daemontools's svc, god, bluepill, node-forever---and supervisord is by far the best.)
The script does not abide by any Twitter backoff requirement, but I've never
had any trouble with backoff being enforced by Twitter. It's more than curl,
though, because it checks that it's receiving data. Often, with curl and
PycURL, my connection would be dropped by Twitter, but no end signal would be sent.
My crawler would simply hang, expecting data, but would not try to reconnect.
But beyond that, without --ttv2, it doesn't provide anything more than curl.
TTV2
TTV2 is the Tweet tab-separated format version 2, the specification is below. Fields are 1-indexed for easy AWKing (see Markdown source for 0-indexing).
- tweet_id
- created_at parsed into YYYYMMDDTHHMMSS, implicitly UTC
- text, newlines and tabs converted to spaces, html entities replaced, t.co urls resolved
- lon,lat
- place_id
- place_str
- inreplytostatusid
- inreplytoscreenname
- retweet_id id of the original tweet
- retweet_count
- user.screen_name
- user.id
- user.created_at parsed into YYYYMMDDTHHMMSS
- user.name
- user.description
- user.location
- user.url
- user.statuses_count
- user.followers_count
- user.friends_count
- user.favourites_count
- user.geo_enabled
- user.default_profile
- user.time_zone
- user.lang
- user.utc_offset
This format is not the default, and will be the output only when you use the --ttv2 option.
Examples
Install json first: npm install json. It's awesome.
twilight stream --filter 'track=bootstrap' | jq -r -c .text
twilight stream --filter 'track=bootstrap' | jq -c '{user.screen_name, text}'
twilight stream --filter 'track=انتخابات' | jq -r -c .text
twilight stream --filter 'track=sarcmark,%F0%9F%91%8F' | jq -r -c .text
It supports unicode: انتخابات is Arabic for "elections," and decodeURIComponent('%F0%9F%91%8F')
is the "CLAPPING HANDS" (U+1F44F) character.
If you use a filter with url-escaped characters in supervisord, note that supervisord Python-interpolates strings, so you'll need to escape the percent signs, e.g.:
[program:slowclap]
command=twitter-curl --filter "track=%%F0%%9F%%91%%8F" --file /tmp/slowclap.json
TTV2 Example
Instead of JSON, you can use AWK to look at the TTV2:
twitter-curl --filter 'track=data,science' --ttv2 | awk 'BEGIN{FS="\t"}{print $4,$3}'
Stats
- RSS usage per-process is between 20-40MB.
- VSZ on a machine running six of these crawlers is 80-90MB.
License
Copyright 2011-2015 Christopher Brown. MIT Licensed.
Owner
- Name: Christopher Brown
- Login: chbrown
- Kind: user
- Location: New York, NY
- Website: https://henrian.com
- Repositories: 345
- Profile: https://github.com/chbrown
GitHub Events
Total
Last Year
Committers
Last synced: over 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Christopher Brown | io@h****m | 148 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 1
- Total pull requests: 2
- Average time to close issues: 10 days
- Average time to close pull requests: 9 months
- Total issue authors: 1
- Total pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.5
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- Shaboo (1)
Pull Request Authors
- dependabot[bot] (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- npm 43 last-month
- pypi 40 last-month
-
Total dependent packages: 1
(may contain duplicates) -
Total dependent repositories: 5
(may contain duplicates) - Total versions: 38
- Total maintainers: 1
npmjs.org: twilight
Twitter API tools
- Homepage: https://github.com/chbrown/twilight
- License: MIT
-
Latest release: 1.0.5
published almost 2 years ago
Rankings
Maintainers (1)
pypi.org: twilight
Twitter (crawling) tools.
- Homepage: http://github.com/chbrown/twilight
- Documentation: https://twilight.readthedocs.io/
- License: Copyright (c) 2011-2013 Christopher Brown Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.3.10
published about 12 years ago
Rankings
Maintainers (1)
Dependencies
- babel-core ^5.0.0 development
- declarations * development
- istanbul * development
- mocha * development
- typescript * development
- lodash ^3.10.1
- loge ^1.0.4
- request ^2.67.0
- streaming 1.0.3
- sv 0.3.9
- yargs ^3.31.0