chronicle-safari 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 614cf4457aa39223f32b25017becd8985b4ff6b32c1c0a8cc3291eaf4276144d
4
+ data.tar.gz: 9591417d0d77242d9cb15d2b4322235ca4bce5ae7f613498ac9c1b1344a7961b
5
+ SHA512:
6
+ metadata.gz: 38faaf11b36a180a947cb2bac98f05cd0967739c61d51278ec4e15583210eb67b34a20cc80939d263b989ce1ec09f8e9b1dd515ae9615a4b6698fbf0b21d6b1c
7
+ data.tar.gz: 103aaa2a76a41caa94d1262fef37d057e459d54ebbf125459fc41d8a7c83b2bd2e56cfd5ac53df79ec0a40a09df922b98e2657b0cb50680c5ccfd1ea667e5204
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ .DS_Store
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andrew@hyfen.net. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in chronicle-pinboard.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Chronicle::Safari
2
+
3
+ Safri plugin for [chronicle-etl](https://github.com/chronicle-app/chronicle-etl)
4
+
5
+ ## Available Connectors
6
+ ### Extractors
7
+ - `safari` - Extractor for history
8
+
9
+ ### Transformers
10
+ - `safari` - Transforms history into Chronicle Schema
11
+
12
+ ## Usage
13
+
14
+ ```sh
15
+ gem install chronicle-etl
16
+ chronicle-etl connectors:install safari
17
+
18
+ chronicle-etl --extractor safari --since 2022-02-07
19
+ ```
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "chronicle/safari"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "chronicle/safari/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "chronicle-safari"
9
+ spec.version = Chronicle::Safari::VERSION
10
+ spec.authors = ["Andrew Louis"]
11
+ spec.email = ["andrew@hyfen.net"]
12
+
13
+ spec.summary = "Safari importer for Chronicle"
14
+ spec.description = "Import your safari history"
15
+ spec.homepage = "https://github.com/chronicle-app/chronicle-safari"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/chronicle-app/chronicle-safari"
24
+ spec.metadata["changelog_uri"] = "https://github.com/chronicle-app/chronicle-safari"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "chronicle-etl", "~> 0.4"
40
+ spec.add_dependency "sqlite3", "~> 1.4"
41
+
42
+ spec.add_development_dependency "bundler", "~> 2.3"
43
+ spec.add_development_dependency "rake", "~> 13.0.6"
44
+ spec.add_development_dependency "pry-byebug", "~> 3.9"
45
+ end
@@ -0,0 +1,75 @@
1
+ require 'chronicle/etl'
2
+ require 'sqlite3'
3
+
4
+ module Chronicle
5
+ module Safari
6
+ class SafariExtractor < Chronicle::ETL::Extractor
7
+ register_connector do |r|
8
+ r.provider = 'safari'
9
+ r.description = 'browser history'
10
+ end
11
+
12
+ setting :input, default: File.join(Dir.home, 'Library', 'Safari', 'history.db'), required: true
13
+ setting :icloud_account_id
14
+ setting :icloud_account_account_dsid
15
+ setting :icloud_account_account_display_name
16
+
17
+ def prepare
18
+ @db = SQLite3::Database.new(@config.input, results_as_hash: true)
19
+ @icloud_account = load_icloud_account
20
+ @history = load_history
21
+ end
22
+
23
+ def extract
24
+ @history.each do |entry|
25
+ entry.transform_keys!(&:to_sym)
26
+ yield Chronicle::ETL::Extraction.new(data: entry, meta: { icloud_account: @icloud_account } )
27
+ end
28
+ end
29
+
30
+ def results_count
31
+ @history.count
32
+ end
33
+
34
+ private
35
+
36
+ def load_icloud_account
37
+ {
38
+ id: @config.icloud_account_id || icloud_account_info_default[:AccountID],
39
+ dsid: @config.icloud_account_dsid || icloud_account_info_default[:AccountDSID],
40
+ display_name: @config.icloud_account_display_name || icloud_account_info_default[:DisplayName]
41
+ }
42
+ end
43
+
44
+ def icloud_account_info_default
45
+ @icloud_account_info_default || begin
46
+ output = `defaults read MobileMeAccounts Accounts | plutil -convert json -r -o - -- -`
47
+ JSON.parse(output, symbolize_names: true).first
48
+ end
49
+ end
50
+
51
+ def load_history
52
+ conditions = []
53
+ conditions << "history_visits.redirect_destination IS NULL"
54
+ conditions << "visit_time_utc > '#{@config.since.utc}'" if @config.since
55
+ conditions << "visit_time_utc < '#{@config.until.utc}'" if @config.until
56
+
57
+ sql = <<~SQL
58
+ SELECT
59
+ *,
60
+ datetime(visit_time + 978307200, 'unixepoch') as visit_time_utc
61
+ FROM
62
+ history_visits
63
+ LEFT JOIN
64
+ history_items
65
+ ON history_items.id = history_item
66
+ SQL
67
+ sql += " WHERE #{conditions.join(" AND ")}" if conditions.any?
68
+ sql += " ORDER BY visit_time_utc DESC"
69
+ sql += " LIMIT #{@config.limit}" if @config.limit
70
+
71
+ results = @db.execute(sql)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,60 @@
1
+ require 'chronicle/etl'
2
+
3
+ module Chronicle
4
+ module Safari
5
+ class SafariTransformer < Chronicle::ETL::Transformer
6
+ register_connector do |r|
7
+ r.provider = 'safari'
8
+ r.description = 'a history item'
9
+ end
10
+
11
+ def transform
12
+ @data = @extraction.data
13
+ build_browsed
14
+ end
15
+
16
+ def id
17
+ # IDs from local db aren't global or stable across multiple installs
18
+ end
19
+
20
+ def timestamp
21
+ Time.parse(@data[:visit_time_utc])
22
+ end
23
+
24
+ private
25
+
26
+ def build_browsed
27
+ record = ::Chronicle::ETL::Models::Activity.new({
28
+ verb: 'browsed',
29
+ provider: 'safari',
30
+ end_at: timestamp
31
+ })
32
+ record.dedupe_on << [:provider, :verb, :end_at]
33
+ record.actor = build_actor
34
+ record.involved = build_involved
35
+ record
36
+ end
37
+
38
+ def build_involved
39
+ record = ::Chronicle::ETL::Models::Entity.new({
40
+ title: @data[:title],
41
+ provider_url: @data[:url],
42
+ })
43
+ record.dedupe_on << [:provider_url]
44
+ record
45
+ end
46
+
47
+ def build_actor
48
+ record = ::Chronicle::ETL::Models::Entity.new({
49
+ represent: 'identity',
50
+ provider: 'icloud',
51
+ provider_id: @extraction.meta[:icloud_account][:dsid],
52
+ title: @extraction.meta[:icloud_account][:display_name],
53
+ slug: @extraction.meta[:icloud_account][:id]
54
+ })
55
+ record.dedupe_on << [:provider, :represents, :slug]
56
+ record
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chronicle
4
+ module Safari
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "safari/version"
4
+ require_relative "safari/safari_extractor"
5
+ require_relative "safari/safari_transformer"
6
+
7
+ module Chronicle
8
+ module Safari
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronicle-safari
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Louis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chronicle-etl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ description: Import your safari history
84
+ email:
85
+ - andrew@hyfen.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - chronicle-safari.gemspec
98
+ - lib/chronicle/safari.rb
99
+ - lib/chronicle/safari/safari_extractor.rb
100
+ - lib/chronicle/safari/safari_transformer.rb
101
+ - lib/chronicle/safari/version.rb
102
+ homepage: https://github.com/chronicle-app/chronicle-safari
103
+ licenses: []
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ homepage_uri: https://github.com/chronicle-app/chronicle-safari
107
+ source_code_uri: https://github.com/chronicle-app/chronicle-safari
108
+ changelog_uri: https://github.com/chronicle-app/chronicle-safari
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Safari importer for Chronicle
128
+ test_files: []