def get_client(): credentials = get_credentials() app, email, password = (credentials[key] for key in ("app", "email", "password")) url = "https://{0}.harvestapp.com".format(app) logger.info(msg="url is {0}".format(url)) return Harvest(url, email, password)
def get_timesheet(): try: URI, USERNAME, PASSWORD = get_credentials() except ConfigParser.NoSectionError: URI, USERNAME, PASSWORD = set_credentials() harvest = Harvest(URI, USERNAME, PASSWORD) return harvest
def setUp(self): personal_access_token = PersonalAccessToken('ACCOUNT_NUMBER', 'PERSONAL_ACCESS_TOKEN') self.harvest = Harvest('https://api.harvestapp.com/api/v2', personal_access_token) warnings.filterwarnings( "ignore", category=ResourceWarning, message="unclosed.*") # There's a bug in httpretty ATM. httpretty.enable()
def __init__(self): self.harvest = Harvest(scratch.url, scratch.username, scratch.password) self.statusIcon = gtk.StatusIcon() self.statusIcon.set_from_stock(gtk.STOCK_ABOUT) self.statusIcon.set_visible(True) self.statusIcon.set_tooltip("Hello World") self.menu = gtk.Menu() sep = gtk.SeparatorMenuItem() self.menu.append(sep) project_menu = gtk.Menu() for client, projects in self.harvest.get_project_in_categories( ).iteritems(): client_item = gtk.MenuItem(client) project_menu.append(client_item) for project in projects: task_menu = gtk.Menu() p = gtk.MenuItem(project['name']) for task in project['tasks']: t = gtk.MenuItem(task['name']) t.connect('activate', self.task_cb, self.menu, { "project": project, "task": task }) task_menu.append(t) p.set_submenu(task_menu) project_menu.append(p) sep = gtk.SeparatorMenuItem() project_menu.append(sep) self.menuItem = gtk.MenuItem('Projects') self.menuItem.set_submenu(project_menu) self.menu.append(self.menuItem) self.menuItem = gtk.ImageMenuItem(gtk.STOCK_QUIT) self.menuItem.connect('activate', self.quit_cb, self.statusIcon) self.menu.append(self.menuItem) self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu) self.statusIcon.set_visible(1) gtk.main()
def __init__(self, path, url): self.document = Document() self.session = Session(name=url, root_url=url) #self.session = Session('load_from_config=False') self.session.use_doc('crawler_dashboard') self.session.load_document(self.document) #self.harvest_source = ColumnDataSource(data=dict()) #self.domain_relevant_source = ColumnDataSource(data=dict()) #self.domain_crawled_source = ColumnDataSource(data=dict()) #self.domain_frontier_source = ColumnDataSource(data=dict()) #self.handson_source = ColumnDataSource(data=dict()) #self.termite_source = ColumnDataSource(data=dict()) self.harvest = Harvest(path) self.domain = Domain(path) #handson = Handson() #self.termite = Termite() self.document.add(self.create_layout()) self.session.store_document(self.document)
def __init__(self): self.document = Document() self.session = Session() self.session.use_doc('crawler_dashboard') self.session.load_document(self.document) #self.harvest_source = ColumnDataSource(data=dict()) #self.domain_relevant_source = ColumnDataSource(data=dict()) #self.domain_crawled_source = ColumnDataSource(data=dict()) #self.domain_frontier_source = ColumnDataSource(data=dict()) #self.handson_source = ColumnDataSource(data=dict()) #self.termite_source = ColumnDataSource(data=dict()) self.harvest = Harvest() self.domain = Domain() #handson = Handson() self.termite = Termite() self.document.add(self.create_layout()) self.session.store_document(self.document)
import re import json import time import requests from harvest import Harvest harvester = Harvest() # ERC20 Transfer Only abiUrl1 = "https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/erc20_transfer_function_only_abi.txt" abiData1 = requests.get(abiUrl1).content abiData1JSON = json.loads(abiData1) theDeterministicHash1 = harvester.shaAnAbi(abiData1JSON) cleanedAndOrderedAbiText1 = harvester.cleanAndConvertAbiToText(abiData1JSON) data1 = {} data1['indexInProgress'] = "false" data1['epochOfLastUpdate'] = int(time.time()) data1['abi'] = cleanedAndOrderedAbiText1 harvester.es.index(index=harvester.abiIndex, id=theDeterministicHash1, body=data1) #v1 abiUrl1 = "https://raw.githubusercontent.com/CyberMiles/smart_contracts/master/FairPlay/v1/dapp/FairPlay.abi" abiData1 = requests.get(abiUrl1).content abiData1JSON = json.loads(abiData1) theDeterministicHash1 = harvester.shaAnAbi(abiData1JSON) cleanedAndOrderedAbiText1 = harvester.cleanAndConvertAbiToText(abiData1JSON)
def __init__(self, num_harvests=3): self.num_harvests = num_harvests self.harvests = [Harvest(i) for i in range(num_harvests)] self.cost = sys.maxsize
def from_solution(self, solution): for i, harvest in enumerate(solution.harvests): self.harvests[i] = Harvest(i) self.harvests[i].from_harvest(harvest)
import time #import simplejson as json import json import mysql.connector from mysql.connector import errorcode #import pprint # Harvest Setup harvest_creds = {'uri': os.getenv("HARVEST_URI"), 'email': os.getenv("HARVEST_EMAIL"), 'password': os.getenv("HARVEST_PASSWORD")} URI = harvest_creds['uri'] EMAIL = harvest_creds['email'] PASS = harvest_creds['password'] h = Harvest(URI,EMAIL,PASS) # Var Setup user_hours={} user_names={} project_hours={} timesheet_punches={} email_html="" # Yesterday - adjust to your liking end = datetime.today().replace( hour=0, minute=0, second=0 ) start = end + timedelta(-1) #mysql_creds = json.loads(open('mysql.json').read()) #mysql_creds = json.loads(os.getenv("MYSQL")) mysql_creds = {'user': os.getenv("MYSQL_USER"),
def __init__(self, crawl): self.crawl = crawl if self.crawl.crawler != "ache": raise ValueError("Crawl must be using the Ache crawler.") self.harvest = Harvest(crawl) self.domain = Domain(crawl)
def sync_hours_for_date(password, date_str): in_date = strptime(date_str, '%d/%m/%Y') doy = in_date.tm_yday print "Syncing %d/%d/%d (%s)" % (in_date.tm_mday, in_date.tm_mon, in_date.tm_year, doy) h = Harvest(HARVEST_URL_ROOT, HARVEST_USER_EMAIL, password) rm = redmine.Redmine(REDMINE_URL_ROOT, key=REDMINE_API_KEY) rm_date = date(*in_date[:3]) rm_users = rm.users rm_user = rm_users[6] day = h.get_day(doy, 2016) activities = rm.time_entry_activities development = None meeting = None proj_man = None for activity in activities: if activity.name == 'Development': development = activity elif activity.name == 'Meeting': meeting = activity if activity.name == 'Project Management': proj_man = activity if development is None or meeting is None or proj_man is None: raise ValueError('Cant find all activity types') at_map = { 'Coding': development, 'Meeting': meeting, 'Project Management': proj_man } for day_entry in day['day_entries']: if day_entry['client'] != CLIENT_NAME: continue activity = at_map.get(day_entry['task']) if not activity: print "Can't map activity '%s'" % day_entry['task'] continue if day_entry['notes'] is not None and 'logged' in day_entry[ 'notes'].lower(): continue elif day_entry['notes'] is None: day_entry['notes'] = '' if activity == development or day_entry['notes'].startswith('#'): if day_entry['notes'].startswith('#'): try: ticket_id = int(day_entry['notes'][1:]) except (TypeError, ValueError): print "Can't parse ID on %s" % day_entry['notes'] continue entry_notes = '' else: print "Not logging {}".format(day_entry['notes']) continue issue = rm.issues[ticket_id] try: te = rm.time_entries.new(issue=issue, activity=activity, spent_on=rm_date.strftime('%Y-%m-%d'), user=rm_user, hours=day_entry['hours'], comments=entry_notes) except Exception as e: print e.read() return if day_entry['notes'] == '': day_entry['notes'] = 'Logged' else: day_entry['notes'] += ' Logged' try: h.update(day_entry['id'], day_entry) except Exception as e: print "Failed to save time for %d. Delete manually" % ticket_id return print "Logged %02f hours for #%d" % (day_entry['hours'], ticket_id)
from datetime import datetime, timedelta from harvest import Harvest h = Harvest( 'https://enjrolas.harvestapp.com', '*****@*****.**', 'planeman' ) user = h.find_user( 'Test', 'Guy' ) if user: print "The user ID = %d" % user.id start = datetime.today()-timedelta(365); end = datetime.today(); total = 0 for entry in user.unbilled_entries( start, end ): print entry total += entry.hours total=0 for expense in user.unbilled_expenses(start,end): print expense total+= print 'Total hours worked = %f' % total