<commit_before>require 'json'

class SearchesController < ApplicationController
	def new
		redirect_to searches_url
	end

	def create
		p "*" * 100
		@search = Search.new({hashtag: params["hashtag"], start_date: params["start_date"], end_date: params["end_date"]})
		@search.save

		response = HTTParty.get('https://api.instagram.com/v1/tags/pixleememories/media/recent?access_token=<KEY>')
		response_body = JSON.parse(response.body)

		if response_body["data"]

			response_body["data"].each do |result|
				filtered_result_data = filter_data(result)
				@result = Result.create(ig_username: filtered_result_data[:ig_username], content_type: filtered_result_data[:content_type], ig_link: filtered_result_data[:ig_link], image_url: filtered_result_data[:image_url], video_url: filtered_result_data[:video_url], description: filtered_result_data[:description], search_id: @search.id)
				end

				p "is there a next page?"
				if has_next_page_link?(response_body)
					p 'yeah, keep going!'
					paginate(response_body["pagination"]["next_url"], @search.id)
				end
		end
		# @search.test
		# write filters to filter out things by date and hash tag inclusion
		# puts response_body["pagination"]

		render json: response_body["pagination"]
	end

	def index
		@searches = Search.all
		render json: @searches
	end
	
	def show
		@search = Search.find(params[:id])
		render json: @search
	end

	private
		def search_params
			params.require(:search).permit(:hashtag, :start_date, :end_date)
		end
end
# filter by date, filter by tag then check case of date and if not move on and so forth
<commit_msg>Pseudocode background job and work flow.<commit_after>require 'json'

class SearchesController < ApplicationController
	def new
		redirect_to searches_url
	end

	def create
		p "*" * 100
		@search = Search.new({hashtag: params["hashtag"], start_date: params["start_date"], end_date: params["end_date"]})
		@search.save

		response = HTTParty.get('https://api.instagram.com/v1/tags/pixleememories/media/recent?access_token=<KEY>')
		response_body = JSON.parse(response.body)

		if response_body["data"]

			response_body["data"].each do |result|
				filtered_result_data = filter_data(result)
				@result = Result.create(ig_username: filtered_result_data[:ig_username], content_type: filtered_result_data[:content_type], ig_link: filtered_result_data[:ig_link], image_url: filtered_result_data[:image_url], video_url: filtered_result_data[:video_url], description: filtered_result_data[:description], search_id: @search.id)
				end

				p "is there a next page?"
				if has_next_page_link?(response_body)
					p 'yeah, keep going!'
					paginate(response_body["pagination"]["next_url"], @search.id)
				end
		end
		# @search.test
		# write filters to filter out things by date and hash tag inclusion
		# puts response_body["pagination"]
		# load more button in the background 
		# rails does have a background job
		#sidekiq

		# make first request, return the first 20, start background job, go back to client
		# create a load more button if there is a next page
		# click the load button and hit a second route in the controller that will make a request that renders the images/videos without storing them because the background job is already going
		render json: @search
	end


	def index
		@searches = Search.all
		render json: @searches
	end
	
	def show
		@search = Search.find(params[:id])
		render json: @search
	end

	private
		def search_params
			params.require(:search).permit(:hashtag, :start_date, :end_date)
		end
end
# filter by date, filter by tag then check case of date and if not move on and so forth

{'fraction_non_alphanumeric': 0.10113290964354794, 'fraction_numerical': 0.0027631942525559545, 'mean_word_length': 4.876623376623376, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3208959', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1125, 'n_words': 328}