<commit_before>require 'dropbox_sdk'
require 'twitter'
require 'open-uri'

get '/sources/new' do 
  @user = current_user 
  erb :'sources/new'
end

get '/sources/add-image' do
  @user = current_user
  client = DropboxClient.new(@user.dropbox_token)
  puts client.metadata('/this-week').inspect
  client.metadata('/this-week')["contents"].each do |image|
    image_path = image["path"]
    content_url = client.media(image_path)["url"]
    dropbox_url = content_url + "?dl=1"
    twitter_media_upload(dropbox_url)
    puts "Posted #{dropbox_url}"
    sleep 60
  end
  # path = client.metadata('/')["contents"][1]["path"]
  # @content_url = client.media(path)["url"]
  # twitter_media_upload(media_url)
  erb :'sources/add-image'
end

#Dropbox Services
get '/sources/dropbox' do 
  flow = dropbox_flow
  authorize_url = flow.start() 
  redirect to (authorize_url)
end

get '/sources/dropbox-complete' do
	flow = dropbox_flow
  @session = session
  user_token= flow.finish(params) 
  @user = current_user 
  @user.dropbox_token = user_token[0]
  @user.save

  client = DropboxClient.new(@user.dropbox_token) 
  make_dropbox_folder("/this-week", client)
  make_dropbox_folder("/archive", client)

  erb :'sources/new'
end

<commit_msg>Add low-level code to tweet a directory of images.<commit_after>require 'dropbox_sdk'
require 'twitter'
require 'open-uri'

get '/sources/new' do 
  @user = current_user 
  erb :'sources/new'
end

get '/sources/add-image' do
  @user = current_user
  client = DropboxClient.new(@user.dropbox_token)
  puts client.metadata('/this-week').inspect
  client.metadata('/this-week')["contents"].each do |image|
    image_path = image["path"]
    content_url = client.media(image_path)["url"]
    dropbox_url = content_url + "?dl=1"
    twitter_media_upload("This is something:", dropbox_url)
    puts "Posted #{dropbox_url}"
    sleep 60
  end
  # path = client.metadata('/')["contents"][1]["path"]
  # @content_url = client.media(path)["url"]
  # twitter_media_upload(media_url)
  erb :'sources/add-image'
end

#Dropbox Services
get '/sources/dropbox' do 
  flow = dropbox_flow
  authorize_url = flow.start() 
  redirect to (authorize_url)
end

get '/sources/dropbox-complete' do
	flow = dropbox_flow
  @session = session
  user_token= flow.finish(params) 
  @user = current_user 
  @user.dropbox_token = user_token[0]
  @user.save

  client = DropboxClient.new(@user.dropbox_token) 
  make_dropbox_folder("/this-week", client)
  make_dropbox_folder("/archive", client)

  erb :'sources/new'
end


{'fraction_non_alphanumeric': 0.1396271320904403, 'fraction_numerical': 0.003966679888932963, 'mean_word_length': 4.412017167381975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995395', 'n_tokens_mistral': 912, 'n_tokens_neox': 885, 'n_words': 179}