dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

flatastic.rb (1195B)


      1 #!/usr/bin/env ruby
      2 require 'uri'
      3 require 'net/http'
      4 require 'json'
      5 require 'time'
      6 
      7 %w[FLATASTIC_API_KEY FLATASTIC_USER_ID].each do |env_var|
      8   abort "#{env_var} not set in environment" unless ENV.key? env_var
      9 end
     10 
     11 my_user_id = ENV['FLATASTIC_USER_ID'].to_i
     12 api_key = ENV['FLATASTIC_API_KEY']
     13 
     14 headers = {
     15   'accept' => 'application/json, text/plain, */*',
     16   'origin' => 'https://app.flatastic-app.com',
     17   'referer' => 'https://app.flatastic-app.com/',
     18   'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
     19   'x-api-key' => api_key,
     20   'x-api-version' => '2.0.0',
     21   'x-client-version' => '2.3.35'
     22 }
     23 
     24 base_url = URI 'https://api.flatastic-app.com'
     25 https = Net::HTTP.new(base_url.host, base_url.port)
     26 https.use_ssl = true
     27 
     28 url = "#{base_url}/index.php/api/chores"
     29 resp = JSON.parse(https.get(url, headers).body)
     30 my_tasks = resp
     31            .select { _1['currentUser'] == my_user_id }
     32            .map { {'description' => _1['title'],
     33                     'scheduled_due_date' => Time.at(Time.now.to_i + _1['timeLeftNext']), # close enough
     34                     'point_value' => _1['points']} }
     35 
     36 print my_tasks.to_json