<commit_before>require "watir-webdriver"
require 'roo-xls'
require "headless"

config = YAML.load(File.read("config.yml"))

browser = nil

if config["browser"] == "chrome" 
  browser = Watir::Browser.new :chrome
else
  browser = Watir::Browser.new
end


browser.goto "http://timetracker.bairesdev.com"

puts "Visiting the site..."

browser.text_field(id: "ctl00_ContentPlaceHolder_UserNameTextBox").set config["user"]
browser.text_field(id: "ctl00_ContentPlaceHolder_PasswordTextBox").set config["password"]

browser.button(id: "ctl00_ContentPlaceHolder_LoginButton").click

if browser.text.include? "Welcome"
  puts "You're in!!!"
else
  puts "Sorry"
end

def worked_hours(file)
  xls = Roo::Spreadsheet.open(file)
  sheet = xls.sheet("Worklogs")
  sheet.parse(
    date: /Work date/,
    hours: /Hours/,
    description: /Work Description/,
    summary: /Issue summary/
  )
end

def work_description(report, config)
  if config["add_issue_summary"]
    "#{report[:summary]}: #{report[:description]}"
  else
    "#{report[:description]}"
  end
end

Dir.glob(File.join(config["directory"], "*.xls")).each do |file|
  puts "="*50
  puts "Processing.... #{file}"
  puts "="*50
  worked_hours(file).each do |report|
    next if report[:date].is_a? String
    next if report[:date].nil? 
    browser.link(text: "Track Hours").click
    browser.text_field(id: "ctl00_ContentPlaceHolder_txtFrom").set report[:date].strftime("%d/%m/%Y")
    browser.select_list(id: "ctl00_ContentPlaceHolder_idProyectoDropDownList").select("iSeatz - iSeatz")
    browser.select_list(id: "ctl00_ContentPlaceHolder_idTipoAsignacionDropDownList").select("Software Development")
    Watir::Wait.until { browser.text_field(id: "ctl00_ContentPlaceHolder_TiempoTextBox").exist? }  
    browser.text_field(id: "ctl00_ContentPlaceHolder_TiempoTextBox").set report[:hours]
    browser.textarea(id: "ctl00_ContentPlaceHolder_DescripcionTextBox").set work_description(report, config)
    sleep(1)
    browser.select_list(id: "ctl00_ContentPlaceHolder_idFocalPointClientDropDownList").select(config["focal_point"])
    sleep(1)
    browser.textarea(id: "ctl00_ContentPlaceHolder_DescripcionTextBox").set work_description(report, config)
    browser.select_list(id: "ctl00_ContentPlaceHolder_idTipoAsignacionDropDownList").select("Software Development")
    browser.text_field(id: "ctl00_ContentPlaceHolder_TiempoTextBox").set report[:hours]
    browser.button(id: "ctl00_ContentPlaceHolder_btnAceptar").click
  end<commit_msg>Fix weird issues with cleaning fields<commit_after>require "watir-webdriver"
require 'roo-xls'
require "headless"

config = YAML.load(File.read("config.yml"))

browser = nil

if config["browser"] == "chrome" 
  browser = Watir::Browser.new :chrome
else
  browser = Watir::Browser.new
end


browser.goto "http://timetracker.bairesdev.com"

puts "Visiting the site..."

browser.text_field(id: "ctl00_ContentPlaceHolder_UserNameTextBox").set config["user"]
browser.text_field(id: "ctl00_ContentPlaceHolder_PasswordTextBox").set config["password"]

browser.button(id: "ctl00_ContentPlaceHolder_LoginButton").click

if browser.text.include? "Welcome"
  puts "You're in!!!"
else
  puts "Sorry"
end

def worked_hours(file)
  xls = Roo::Spreadsheet.open(file)
  sheet = xls.sheet("Worklogs")
  sheet.parse(
    date: /Work date/,
    hours: /Hours/,
    description: /Work Description/,
    summary: /Issue summary/
  )
end

def work_description(report, config)
  if config["add_issue_summary"]
    "#{report[:summary]}: #{report[:description]}"
  else
    "#{report[:description]}"
  end
end

Dir.glob(File.join(config["directory"], "*.xls")).each do |file|
  puts "="*50
  puts "Processing.... #{file}"
  puts "="*50
  worked_hours(file).each do |report|
    next if report[:date].is_a? String
    next if report[:date].nil? 
    browser.link(text: "Track Hours").click
    browser.text_field(id: "ctl00_ContentPlaceHolder_txtFrom").set report[:date].strftime("%d/%m/%Y")
    browser.select_list(id: "ctl00_ContentPlaceHolder_idProyectoDropDownList").select("iSeatz - iSeatz")
    sleep(1)
    browser.select_list(id: "ctl00_ContentPlaceHolder_idFocalPointClientDropDownList").select(config["focal_point"])
    sleep(1)
    browser.select_list(id: "ctl00_ContentPlaceHolder_idTipoAsignacionDropDownList").select("Software Development")
    sleep(1)
    Watir::Wait.until { browser.text_field(id: "ctl00_ContentPlaceHolder_TiempoTextBox").exist? }  
    browser.text_field(id: "ctl00_ContentPlaceHolder_TiempoTextBox").set report[:hours]
    sleep(1)
    browser.textarea(id: "ctl00_ContentPlaceHolder_DescripcionTextBox").set work_description(report, config)
    browser.textarea(id: "ctl00_ContentPlaceHolder_DescripcionTextBox").set work_description(report, config)
    browser.button(id: "ctl00_ContentPlaceHolder_btnAceptar").click
  end
{'fraction_non_alphanumeric': 0.13909618573797677, 'fraction_numerical': 0.013681592039800995, 'mean_word_length': 5.834277620396601, '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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '590140', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1600, 'n_words': 268}