Skip to content

Commit

Permalink
Merge pull request #75 from true-runes/development
Browse files Browse the repository at this point in the history
v1.4.0
  • Loading branch information
nikukyugamer committed Jun 5, 2021
2 parents 9015caf + 8a860f6 commit 9becd98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/lib/google_sheet_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(credentials_path: nil, token_path: nil)
def create
service = Google::Apis::SheetsV4::SheetsService.new
service.client_options.application_name = APPLICATION_NAME
service.request_options.retries = 3
service.authorization = authorize

service
Expand Down
32 changes: 24 additions & 8 deletions app/lib/google_sheet_api/write_to_response_api_sheet_by_hashtag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ def initialize(spreadsheet_id: nil, sheet_name: nil)
set_basic_valiables
end

def execute(hashtag)
update_data(target_tweets(hashtag))
def execute(hashtag, options={})
update_data(target_tweets(hashtag, options))
rescue StandardError => e
Rails.logger.fatal 'FATAL エラーです: GoogleSheetApi::GoogleSheetApi#execute'
Rails.logger.fatal e if e.present?

bugsnag_error_message = "FATAL エラーです: GoogleSheetApi::GoogleSheetApi#execute / #{e}"
Bugsnag.notify(bugsnag_error_message)
end

# 既存のデータを読み込み、新規のデータをその後ろにくっつけ、それを貼り付けている
Expand All @@ -38,15 +44,25 @@ def update_data(tweets)
)
end

def target_tweets(hashtag)
# TODO: not_retweet だったり '2021-05-01' をハードコーディングしたりしてるのは微妙
def target_tweets(hashtag, options={})
# 初回操作対応
beginning_search_tweet_id_number = @max_tweet_id_number.present? ? @max_tweet_id_number + 1 : 1

Tweet.not_retweet.contains_hashtag(hashtag).not_by_gensosenkyo.where(
id_number: beginning_search_tweet_id_number..
).where(
tweeted_at: Time.zone.parse('2021-05-01')..
).order(tweeted_at: :asc)
if options[:raw_log] == true
Tweet.contains_hashtag(hashtag).where(
id_number: beginning_search_tweet_id_number..
).where(
tweeted_at: Time.zone.parse('2021-04-01')..
).order(tweeted_at: :asc)
else
# not_retweet, contains_hashtag, not_by_gensosenkyo, tweeted_at
Tweet.not_retweet.contains_hashtag(hashtag).not_by_gensosenkyo.where(
id_number: beginning_search_tweet_id_number..
).where(
tweeted_at: Time.zone.parse('2021-05-01')..
).order(tweeted_at: :asc)
end
end

def set_basic_valiables
Expand Down

0 comments on commit 9becd98

Please sign in to comment.