<commit_before>#!/usr/bin/ruby
# Upload kickstarter orders from a CSV to the TPR-Coordinator
# 
# Usage: python import_orders_from_csv.py <path_to_csv>
require 'CSV'
require 'httparty'
 
# Import CSV
backers_csv = CSV.read(ARGV[0])
headers = backers_csv.shift

backer_list = []

backers_csv.each do |backer|
	hash = {}
	headers.each_with_index do |header,i|
		hash[header] = backer[i]
	end
	backer_list << hash
end

backer_list.each do |backer|
	if !backer['Shipping Name'].nil?
		name = backer['Shipping Name']
	else
		name = backer['Backer Name']
	end

	order_params = {
	  name: name,
	  order_source: "kickstarter",
	  email: backer['Email'],
	  street_address_1: backer['Shipping Address 1'],
	  street_address_2: backer['Shipping Address 2'],
	  city: backer['Shipping City'],
	  state: backer['Shipping State'],
	  postal_code: backer['Shipping Postal Code'],
	  country: backer['Shipping Country Code'],
	  phone: backer['Shipping Phone Number']
	}	

	frequencies = []

	backer.select{ |s| s.include?('Radio') }.each do |k,v|
		frequencies << v
	end

	order_params['frequencies'] = { backer['Shipping Country Code']  => frequencies.compact }

	# Post to TPR Coordinator
	url = 'https://api.thepublicrad.io/orders'
	headers = {'Content-Type' => 'application/json'}
  
  response = HTTParty.post(url, headers: headers, body: order_params.to_json)

  if (200..299).include?(response.code)
  	puts 'Success!'
  else
  	puts "An error occured uplading order #{order_params}: #{response.body}"
  end
end;nil<commit_msg>Updating load order script to have auth header<commit_after>#!/usr/bin/ruby
# Upload kickstarter orders from a CSV to the TPR-Coordinator
# 
# Usage: python import_orders_from_csv.py <path_to_csv>
require 'CSV'
require 'httparty'
 
# Import CSV
backers_csv = CSV.read(ARGV[0])
headers = backers_csv.shift

backer_list = []

backers_csv.each do |backer|
	hash = {}
	headers.each_with_index do |header,i|
		hash[header] = backer[i]
	end
	backer_list << hash
end

backer_list.each do |backer|
	if !backer['Shipping Name'].nil?
		name = backer['Shipping Name']
	else
		name = backer['Backer Name']
	end

	order_params = {
	  name: name,
	  order_source: "kickstarter",
	  email: backer['Email'],
	  street_address_1: backer['Shipping Address 1'],
	  street_address_2: backer['Shipping Address 2'],
	  city: backer['Shipping City'],
	  state: backer['Shipping State'],
	  postal_code: backer['Shipping Postal Code'],
	  country: backer['Shipping Country Code'],
	  phone: backer['Shipping Phone Number']
	}	

	frequencies = []

	backer.select{ |s| s.include?('Radio') }.each do |k,v|
		frequencies << v
	end

	order_params['frequencies'] = { backer['Shipping Country Code']  => frequencies.compact }

	# Post to TPR Coordinator
	url = 'https://api-staging.thepublicrad.io/orders'
	headers = {'Authorization' => 'Bearer 1bXdA4I8r10gmMEDT5S4n0yNwyR8BlzB', 'Content-Type' => 'application/json'}
  
  response = HTTParty.post(url, headers: headers, body: order_params.to_json)

  if (200..299).include?(response.code)
  	puts 'Success!'
  else
  	puts "An error occured uplading order #{order_params}: #{response.body}"
  end
end;nil
{'fraction_non_alphanumeric': 0.13736089030206677, 'fraction_numerical': 0.00985691573926868, 'mean_word_length': 4.648114901256733, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '5492393', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1127, 'n_words': 269}