Example #1
0
def update_harvest_projects(request):    
    """
        Update all projects from harvest.
        
        sequence 2/3
    """
    response = []
    h = Harvest( settings.HARVEST_ADDRESS, settings.HARVEST_USER, settings.HARVEST_PASS )
    for hproject in h.projects():
        existing = False
        try:
            p = Project.objects.get(harvest_id=hproject.id)
            response.append({'harvest_id':hproject.id,'name':p.name,'status':'skipped'})
            existing = True
        except:
            p = Project(harvest_id=hproject.id,name=hproject.name, notes=hproject.notes, client=Client.objects.get(harvest_id=hproject.client_id))
            response.append({'harvest_id':hproject.id,'name':hproject.name,'status':'added'})
        
        p.save()  
        
        if not existing:
            # get task assignments per project
            for assignment in hproject.task_assignments:
                try:
                    t = TaskType.objects.get(harvest_id=assignment.task_id)
                except:
                    t = TaskType(harvest_id=assignment.task_id)
                t.save()
                t.projects.add(p)
                response.append({"tasktype":assignment.task_id, "created":True})
                #time.sleep(5)
    return HttpResponse(simplejson.dumps(response,indent=2, ensure_ascii=False),mimetype='application/json') 
Example #2
0
 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()
Example #3
0
    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 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)
Example #5
0
def get_timesheet():
    try:
        URI, USERNAME, PASSWORD = get_credentials()
    except ConfigParser.NoSectionError:
        URI, USERNAME, PASSWORD = set_credentials()

    harvest = Harvest(URI, USERNAME, PASSWORD)
    return harvest
Example #6
0
def get_harvest_clients(request):
    """
        Import new clients from harvest
    
        sequence 1/3
    """
    h = Harvest( settings.HARVEST_ADDRESS, settings.HARVEST_USER, settings.HARVEST_PASS )
    response = []
    for hclient in h.clients():
        try:
            c = Client.objects.get(harvest_id=hclient.id)
            response.append({'harvest_id':hclient.id,'name':c.name,'status':'skipped'})
        except:
            c = Client(harvest_id=hclient.id,name=hclient.name, details=hclient.details)
            response.append({'harvest_id':hclient.id,'name':hclient.name,'status':'added'})
        c.save()
    return HttpResponse(simplejson.dumps(response,indent=2, ensure_ascii=False),mimetype='application/json')
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
def update_harvest_tasks(request):    
    """
        Update all tasks from harvest.

        This isn't particularly big or clever,
        needs to watch out for api rate limit
        (15 reqs per 40 secs)
        
        sequence 3/3
    """
    response = []
    h = Harvest( settings.HARVEST_ADDRESS, settings.HARVEST_USER, settings.HARVEST_PASS )
    for htask in h.tasks():
        try:
            t = TaskType.objects.get(harvest_id=htask.id)
            t.name = htask.name
            response.append({'harvest_id':htask.id,'name':htask.name,'status':'updated'})
        except:
            TaskType(harvest_id=htask.id,name=htask.name)
            response.append({'harvest_id':htask.id,'name':htask.name,'status':'added'})
        t.save()
    return HttpResponse(simplejson.dumps(response,indent=2, ensure_ascii=False),mimetype='application/json')  
Example #10
0
class TestHarvest(unittest.TestCase):
    
    def setUp(self):
        self.harvest = Harvest(URL, USER, PWD)
        
    def test_00_isinstance(self):
        self.assertIsInstance(self.harvest,Harvest)
        
    def test_01_connect_fail(self):
        bad_harvest = Harvest(URL, "bogus_user","badpassword")
        self.assertRaises(Exception,bad_harvest._request, URL + "/people")
        
    def test_02_get_users(self):
        for user in self.harvest.users():
            self.assertIsInstance(user, User)
                
    def test_03_get_invoices(self):
        for inv in self.harvest.invoices():
            self.assertIsInstance(inv, Invoice)
                
    def test_04_get_clients(self):
        for client in self.harvest.clients():
            self.assertIsInstance(client, Client)
Example #11
0
def worked_hours(request):
    h = Harvest( os.environ['HARVEST_URL'], os.environ['HARVEST_USERNAME'], os.environ['HARVEST_PASSWORD'] )
    users = (
        {'firstname': 'Luca', 'lastname': 'Bravo', 'hours': 0},
        {'firstname': 'Antonio', 'lastname': 'Molinari', 'hours': 0},
    )
    for u in users:
        user = h.find_user( u['firstname'], u['lastname'] )
    	if user:
            start = datetime.today()
            end = start + timedelta(7)
            total = 0
            for entry in user.entries( start, end ):
                    total += entry.hours
            u['hours'] = total


    #return HttpResponse('Reports')   
    return render_to_response('worked_hours.html', {
            'version': 1,
            'users': users,
        },
        RequestContext(request)
    )
Example #12
0
 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()
Example #13
0
class AcheDashboard(object):
    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 get_harvest_plot(self):
        # TODO: Remove Pokemon exception catching
        try:
            script, div = self.harvest.create()
        except:
            return [None, None]
        return [script, div]

    def get_domain_plot(self):
        # TODO: Remove Pokemon exception catching
        try:
            script, div = self.domain.create()
        except Exception:
            return [None, None]
        return [script, div]

    def get_relevant_seeds(self):
        # Converts string to StringIO to allow pandas to read it as a file
        seeds = pd.read_csv(StringIO(self.domain.get_relevant_data()),
                            delimiter='\t',
                            header=None,
                            names=['url', 'timestamp'])
        return seeds['url'].to_dict().values()

    def get_plots(self):
        harvest_plot = self.get_harvest_plot()
        domain_plot = self.get_domain_plot()
        if harvest_plot != [None, None]:
            return {
                'scripts': [domain_plot[0], harvest_plot[0]],
                'divs': [domain_plot[1], harvest_plot[1]],
            }
        else:
            return {
                'scripts': None,
                'divs': None,
            }
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
class AcheDashboard(object):

    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 get_harvest_plot(self):
        # TODO: Remove Pokemon exception catching
        try:
            script, div = self.harvest.create()
        except:
            return [None, None]
        return [script, div]

    def get_domain_plot(self):
        # TODO: Remove Pokemon exception catching
        try:
            script, div = self.domain.create()
        except Exception:
            return [None, None]
        return [script, div]

    def get_relevant_seeds(self):
        # Converts string to StringIO to allow pandas to read it as a file
        seeds = pd.read_csv(StringIO(self.domain.get_relevant_data()),
                           delimiter='\t', header=None,
                           names=['url', 'timestamp'])
        return seeds['url'].to_dict().values()

    def get_plots(self):
        harvest_plot = self.get_harvest_plot()
        domain_plot = self.get_domain_plot()
        return {
            'scripts': [domain_plot[0], harvest_plot[0]],
            'divs': [domain_plot[1], harvest_plot[1]],
        }
Example #17
0
    def __init__(self):
        self.load_config()
        self.harvest = Harvest(self.url, self.email, self.password)
        if self.oncall:
            self.hours_worked = random.randrange(self.oncall_min_hours, self.oncall_max_hours)
            self.work_sat = True
            self.work_sun = True
        else:
            self.hours_worked = random.randrange(self.min_hours, self.max_hours)
            self.work_sat = random.randrange(0,2)
            self.work_sun = random.randrange(0,2)

        self.num_days_worked = 5
        if self.work_sat:
            self.num_days_worked += 1
        if self.work_sun:
            self.num_days_worked += 1

        if self.oncall:
            self.daily_incident_hours = floor((self.hours_worked * self.oncall_incident_percent) / self.num_days_worked)
            self.daily_automation_hours = floor((self.hours_worked * (1 - self.oncall_incident_percent)) / self.num_days_worked)
        else:
            self.daily_incident_hours = floor((self.hours_worked * self.incident_percent) / self.num_days_worked)
            self.daily_automation_hours = floor((self.hours_worked * (1 - self.incident_percent)) / self.num_days_worked)
Example #18
0
 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
import json
from harvest import Harvest

harvester = Harvest()

# Official ABI copied verbatim from the ETH Wiki at https://github.com/ethereum/wiki/wiki/Contract-ERC20-ABI
officialERC20Abi = '''[
    {
        "constant": true,
        "inputs": [],
        "name": "name",
        "outputs": [
            {
                "name": "",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": false,
        "inputs": [
            {
                "name": "_spender",
                "type": "address"
            },
            {
                "name": "_value",
                "type": "uint256"
Example #20
0
class DashBoard(object):
    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 render(self):
        self.create_layout()
        self.document.add(self.layout)
        self.update_data()

    def create_layout(self):

        #button = Button(label="Randomize data", type="success")
        #button.on_click(update_data)
        #top_panel = HBox(children=[button, self.harvest.plot, self.harvest.rate_plot])
        top_panel = HBox(children=[self.harvest.plot, self.harvest.rate_plot])
        domains = VBox(children=[
            self.domain.sort_relevant_plot, self.domain.sort_crawled_plot,
            self.domain.sort_frontier_plot
        ],
                       width=200)
        #middle_panel = HBox(children=[domains, handson.plot])
        middle_panel = HBox(children=[domains])
        layout = VBox(children=[top_panel, middle_panel])
        self.layout = layout
        return layout

    def update_data(self):

        self.harvest.source = self.harvest.update_source()
        self.domain.sort_relevant_source, self.domain.sort_crawled_source, self.domain.sort_frontier_source = self.domain.update_source(
        )
        #self.termite.data, self.termite.source = self.termite.update_source()
        #self.session.store_objects(ds)
        self.session.store_document(self.document)

    def run(self, poll_interval=0.5):
        #link = self.session.object_link(self.document.context)
        #print("Please visit %s to see the plots (press ctrl-C to exit)" % link)

        try:
            while True:
                self.update_data()
                self.session.load_document(self.document)
                time.sleep(poll_interval)
        except KeyboardInterrupt:
            print()
        except ConnectionError:
            print("Connection to bokeh-server was terminated")
Example #21
0
class TestHarvest(unittest.TestCase):
    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 teardown(self):
        httpretty.reset()
        httpretty.disable()

    def test_HTTP_500(self):

        user_1782884_dict = {
            "id":
            1782884,
            "first_name":
            "Bob",
            "last_name":
            "Powell",
            "email":
            "*****@*****.**",
            "telephone":
            "",
            "timezone":
            "Mountain Time (US & Canada)",
            "has_access_to_all_future_projects":
            False,
            "is_contractor":
            False,
            "is_admin":
            True,
            "is_project_manager":
            False,
            "can_see_rates":
            True,
            "can_create_projects":
            True,
            "can_create_invoices":
            True,
            "is_active":
            True,
            "created_at":
            "2017-06-26T20:41:00Z",
            "updated_at":
            "2017-06-26T20:42:25Z",
            "weekly_capacity":
            126000,
            "default_hourly_rate":
            100.0,
            "cost_rate":
            75.0,
            "roles": ["Founder", "CEO"],
            "avatar_url":
            "https://cache.harvestapp.com/assets/profile_images/allen_bradley_clock_tower.png?1498509661"
        }
        me = from_dict(data_class=User, data=user_1782884_dict)

        # get_currently_authenticated_user
        httpretty.register_uri(httpretty.GET,
                               "https://api.harvestapp.com/api/v2/users/me",
                               body=json.dumps(user_1782884_dict),
                               status=500)

        with self.assertRaises(HarvestError) as context:
            self.harvest.get_currently_authenticated_user()

        self.assertTrue('There was a server error for your request.' in str(
            context.exception))

        httpretty.reset()

    def test_HTTP_429(self):

        user_1782884_dict = {
            "id":
            1782884,
            "first_name":
            "Bob",
            "last_name":
            "Powell",
            "email":
            "*****@*****.**",
            "telephone":
            "",
            "timezone":
            "Mountain Time (US & Canada)",
            "has_access_to_all_future_projects":
            False,
            "is_contractor":
            False,
            "is_admin":
            True,
            "is_project_manager":
            False,
            "can_see_rates":
            True,
            "can_create_projects":
            True,
            "can_create_invoices":
            True,
            "is_active":
            True,
            "created_at":
            "2017-06-26T20:41:00Z",
            "updated_at":
            "2017-06-26T20:42:25Z",
            "weekly_capacity":
            126000,
            "default_hourly_rate":
            100.0,
            "cost_rate":
            75.0,
            "roles": ["Founder", "CEO"],
            "avatar_url":
            "https://cache.harvestapp.com/assets/profile_images/allen_bradley_clock_tower.png?1498509661"
        }
        me = from_dict(data_class=User, data=user_1782884_dict)

        # get_currently_authenticated_user
        httpretty.register_uri(httpretty.GET,
                               "https://api.harvestapp.com/api/v2/users/me",
                               body=json.dumps(user_1782884_dict),
                               status=429)

        with self.assertRaises(HarvestError) as context:
            self.harvest.get_currently_authenticated_user()

        self.assertTrue(
            'Your request has been throttled.' in str(context.exception))

        httpretty.reset()

    def test_HTTP_422(self):

        user_1782884_dict = {
            "id":
            1782884,
            "first_name":
            "Bob",
            "last_name":
            "Powell",
            "email":
            "*****@*****.**",
            "telephone":
            "",
            "timezone":
            "Mountain Time (US & Canada)",
            "has_access_to_all_future_projects":
            False,
            "is_contractor":
            False,
            "is_admin":
            True,
            "is_project_manager":
            False,
            "can_see_rates":
            True,
            "can_create_projects":
            True,
            "can_create_invoices":
            True,
            "is_active":
            True,
            "created_at":
            "2017-06-26T20:41:00Z",
            "updated_at":
            "2017-06-26T20:42:25Z",
            "weekly_capacity":
            126000,
            "default_hourly_rate":
            100.0,
            "cost_rate":
            75.0,
            "roles": ["Founder", "CEO"],
            "avatar_url":
            "https://cache.harvestapp.com/assets/profile_images/allen_bradley_clock_tower.png?1498509661"
        }
        me = from_dict(data_class=User, data=user_1782884_dict)

        # get_currently_authenticated_user
        httpretty.register_uri(httpretty.GET,
                               "https://api.harvestapp.com/api/v2/users/me",
                               body=json.dumps(user_1782884_dict),
                               status=422)

        with self.assertRaises(HarvestError) as context:
            self.harvest.get_currently_authenticated_user()

        self.assertTrue('There were errors processing your request.' in str(
            context.exception))

        httpretty.reset()

    def test_HTTP_404(self):

        user_1782884_dict = {
            "id":
            1782884,
            "first_name":
            "Bob",
            "last_name":
            "Powell",
            "email":
            "*****@*****.**",
            "telephone":
            "",
            "timezone":
            "Mountain Time (US & Canada)",
            "has_access_to_all_future_projects":
            False,
            "is_contractor":
            False,
            "is_admin":
            True,
            "is_project_manager":
            False,
            "can_see_rates":
            True,
            "can_create_projects":
            True,
            "can_create_invoices":
            True,
            "is_active":
            True,
            "created_at":
            "2017-06-26T20:41:00Z",
            "updated_at":
            "2017-06-26T20:42:25Z",
            "weekly_capacity":
            126000,
            "default_hourly_rate":
            100.0,
            "cost_rate":
            75.0,
            "roles": ["Founder", "CEO"],
            "avatar_url":
            "https://cache.harvestapp.com/assets/profile_images/allen_bradley_clock_tower.png?1498509661"
        }
        me = from_dict(data_class=User, data=user_1782884_dict)

        # get_currently_authenticated_user
        httpretty.register_uri(httpretty.GET,
                               "https://api.harvestapp.com/api/v2/users/me",
                               body=json.dumps(user_1782884_dict),
                               status=404)

        with self.assertRaises(HarvestError) as context:
            self.harvest.get_currently_authenticated_user()

        self.assertTrue('The object you requested can’t be found.' in str(
            context.exception))

        httpretty.reset()

    def test_HTTP_403(self):

        user_1782884_dict = {
            "id":
            1782884,
            "first_name":
            "Bob",
            "last_name":
            "Powell",
            "email":
            "*****@*****.**",
            "telephone":
            "",
            "timezone":
            "Mountain Time (US & Canada)",
            "has_access_to_all_future_projects":
            False,
            "is_contractor":
            False,
            "is_admin":
            True,
            "is_project_manager":
            False,
            "can_see_rates":
            True,
            "can_create_projects":
            True,
            "can_create_invoices":
            True,
            "is_active":
            True,
            "created_at":
            "2017-06-26T20:41:00Z",
            "updated_at":
            "2017-06-26T20:42:25Z",
            "weekly_capacity":
            126000,
            "default_hourly_rate":
            100.0,
            "cost_rate":
            75.0,
            "roles": ["Founder", "CEO"],
            "avatar_url":
            "https://cache.harvestapp.com/assets/profile_images/allen_bradley_clock_tower.png?1498509661"
        }
        me = from_dict(data_class=User, data=user_1782884_dict)

        # get_currently_authenticated_user
        httpretty.register_uri(httpretty.GET,
                               "https://api.harvestapp.com/api/v2/users/me",
                               body=json.dumps(user_1782884_dict),
                               status=403)

        with self.assertRaises(HarvestError) as context:
            self.harvest.get_currently_authenticated_user()

        self.assertTrue(
            'The object you requested was found but you don’t have authorization to perform your request.'
            in str(context.exception))

        httpretty.reset()

    def test_assemble_query_string_bool_lower(self):
        target_query_string = "is_active=false&is_billed=true&page=1&per_page=100"
        key_words = {"is_active": False, "is_billed": True}
        query_string = assemble_query_string(**key_words)
        self.assertEqual(query_string, target_query_string)

    def test_assemble_query_string_page(self):
        target_query_string = "page=10&per_page=100"
        key_words = {'page': 10}
        query_string = assemble_query_string(**key_words)
        self.assertEqual(query_string, target_query_string)

    def test_assemble_query_string_per_page(self):
        target_query_string = "per_page=10&page=1"
        key_words = {'per_page': 10}
        query_string = assemble_query_string(**key_words)
        self.assertEqual(query_string, target_query_string)
Example #22
0
 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)
Example #23
0
import re
import json
import requests
from harvest import Harvest
harvester = Harvest()

# RAW text of ABIs for sorting and hashing
abiUrls = []
abiUrls.append(
    "https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/erc20abi.txt"
)
abiUrls.append(
    "https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/erc20Abi2.txt"
)


def listAbiLength(_abi):
    print("The ABI has " + str(len(_abi)) + " items.")
    print("\n")


# List outputs
def listWholeKeysAndValues(_abi):
    for listItem in _abi:
        for k, v in listItem.items():
            print(str(k) + ": " + str(v))
        print("\n")
    print("\n")


# List types
import re
import json
import time
import requests
from harvest import Harvest
from web3.auto import w3

harvester = Harvest()

abiUrl1 = "https://raw.githubusercontent.com/Uniswap/contracts-vyper/master/abi/uniswap_exchange.json"

abiData1 = requests.get(abiUrl1).content
abiData1JSON = json.loads(abiData1)
theDeterministicHash1 = harvester.shaAnAbi(abiData1JSON)
print("The Uniswap exchange contract ABI SHA is: " + theDeterministicHash1)
cleanedAndOrderedAbiText1 = harvester.cleanAndConvertAbiToText(abiData1JSON)
data2 = {}
data2['indexInProgress'] = "false"
data2['epochOfLastUpdate'] = int(time.time())
data2['abi'] = cleanedAndOrderedAbiText1
#harvester.es.index(index=harvester.abiIndex, id=theDeterministicHash1, body=data2)

# Get the events
abi = [{
    "name":
    "NewExchange",
    "inputs": [{
        "type": "address",
        "name": "token",
        "indexed": True
    }, {
Example #25
0
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"),
import re
import json
import time
import math
import requests
from harvest import Harvest
import elasticsearch.helpers
from flask import Flask, jsonify, request

harvester = Harvest()

app = Flask(__name__)


def logApi(_request):
    data = {}
    timestamp = math.floor(time.time())
    data["timestamp"] = timestamp
    callingIp = _request.headers.get('X-Forwarded-For', request.remote_addr)
    data["callingIp"] = callingIp
    endpoint = _request.endpoint
    data["endpoint"] = endpoint
    harvester.processApiAccessLog(data)


@app.route("/api/get_block_interval", methods=['GET', 'POST'])
def get_block_interval():
    blockInterval = harvester.getBlockInterval()
    logApi(request)
    return jsonify(blockInterval)
Example #27
0
        if args.date == 'today':
            min_date = today
        elif re.match(r'[+-][0-9]*$', args.date):
            min_date = today + timedelta(int(args.date))
        elif re.match(r'[0-9]{8}$', args.date):
            min_date = datetime.strptime(args.date, '%Y%m%d')
        else:
            print('error: unrecognized date format: {0}'.format(args.date))
            exit(1)
    else:
        min_date = today - timedelta(60)

    searchterm = args.search

    harvest = Harvest(
        config.get('harvest', 'url'),
        config.get('harvest', 'user'),
        config.get('harvest', 'pass'))

    entries = reduce(lambda l1, l2: l1 + l2,
                     [harvest.get_day(
                         day_of_the_year=day, year=year)['day_entries']
                      for day, year in harvest_date_range(min_date, today)])
    matches = filter(lambda entry: searchterm in entry['notes'], entries)
    total_hours = sum([entry['hours'] for entry in matches])
    pprint(matches)
    print('Total hours: ' + str(total_hours))

    old_tasks = set([entry['task'] for entry in matches])
    print('Booked tasks: {0}.'.format(', '.join(old_tasks)))

    if args.new_task:
import os
from datetime import datetime, timedelta
from harvest import Harvest, HarvestError
from spreadsheets_util import *

h = Harvest( os.environ['HARVEST_URL'], os.environ['HARVEST_EMAIL'], os.environ['HARVEST_PASSWORD'] )

end = datetime.today()
start = end - timedelta(720) # 2 Years in the past

gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = os.environ['GDOCS_EMAIL']
gd_client.password = os.environ['GDOCS_PASSWORD']
gd_client.source = 'opengeo-solutions_dashboard-1'
gd_client.ProgrammaticLogin()
#gd_client.debug = True

key = '0AgQ7XY0Atfx5dERpQ2VDcEtGUVpOQVRvVng4Tm1DMGc'
worksheet = 'od6'

def update_project(row, name, client, total, billable, non_billable):
    CellsUpdateAction(gd_client, key, worksheet, row, 1, name)
    CellsUpdateAction(gd_client, key, worksheet, row, 2, client)
    CellsUpdateAction(gd_client, key, worksheet, row, 3, str(total))
    CellsUpdateAction(gd_client, key, worksheet, row, 4, str(billable))
    CellsUpdateAction(gd_client, key, worksheet, row, 5, str(non_billable))

project_count = 1
for project in h.projects():
    total = 0
    tasks = {}
import re
import json
import time
import eth_abi
import requests
from itertools import chain
from harvest import Harvest

# import functools
# from web3.contract import get_event_data

harvester = Harvest()
latestBlockNumber = harvester.web3.eth.getBlock('latest').number

# Iterate through the individual blocks looking for a transaction which involves event log emit
# TESTING SINGLE EVENT AT BLOCK 6328976
while True:
    latestBlockNumber = harvester.web3.eth.getBlock('latest').number
    for b in range(latestBlockNumber - 10, latestBlockNumber):
        transactionCount = harvester.web3.eth.getBlockTransactionCount(b)
        #transactionCount = harvester.web3.eth.getBlockTransactionCount(6509882)
        if (transactionCount >= 1):
            for singleTransactionInt in range(0, transactionCount):
                transaction = harvester.web3.eth.getTransactionByBlock(
                    b, singleTransactionInt)
                # transaction = harvester.web3.eth.getTransactionByBlock(6509882, singleTransactionInt)
                transactionHash = transaction.hash
                # Check to see if this TxHash is indexed
                transactionReceipt = harvester.web3.eth.getTransactionReceipt(
                    transaction.hash)
                transactionLogs = transactionReceipt.logs
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)
import re
import json
import requests
from harvest import Harvest
harvester = Harvest()

# RAW text of ABIs for sorting and hashing
abiUrls = []
abiUrls.append(
    "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/vanilla.txt"
)
abiUrls.append(
    "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/increaseApproval_inputs_reversed.txt"
)
abiUrls.append(
    "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_cmt_abis_for_testing/master/random.txt"
)

outputHashes = []
for singleAbiUrl in abiUrls:
    print("Processing: " + singleAbiUrl)
    singleAbiString = requests.get(singleAbiUrl).content
    singleAbiJSON = json.loads(singleAbiString)
    singleHash = harvester.shaAnAbi(singleAbiJSON)
    outputHashes.append(singleHash)
print("Output hashes are as follows, these should all be exactly the same")
for singleHash in outputHashes:
    print(singleHash)
Example #32
0
import json
import requests
from harvest import Harvest
harvester = Harvest()

source = '''{
                    "TxHash": "0x233e6634b6e713fae69799305794cb679c9a3a89181a3f391d5971df5beaf7d6",
                    "abiShaList": [
                        "0x50d9155267cb10b61afba8628bdc6181de9af836918d7987c2c421512256ab82"
                    ],
                    "blockNumber": 4964970,
                    "creator": "0xb156929f55c48265607fd87b9e2d6fcceee6726a",
                    "contractAddress": "0xA362e5Bc203AEA01C398B74aA6e36d144E96712f",
                    "functionDataList": {
                        "0": [
                            {
                                "functionDataId": "0x3a851ba992dd5464cc247cb21fb0a92a11dd417fc2a028fcbede22ef693efc6d",
                                "functionData": {
                                    "name": "Arcblock Token",
                                    "totalSupply": "1000000000000000000000000000",
                                    "decimals": "18",
                                    "symbol": "ABT"
                                },
                                "uniqueAbiAndAddressHash": "0x54040994221542e1ce9fdfc9c7396d02de07a2b7df065865b8a404a5498c6fef"
                            }
                        ]
                    },
                    "requiresUpdating": "yes",
                    "quality": "50",
                    "indexInProgress": "false"
                }'''
Example #33
0
class Timecard():
    def __init__(self):
        self.load_config()
        self.harvest = Harvest(self.url, self.email, self.password)
        if self.oncall:
            self.hours_worked = random.randrange(self.oncall_min_hours, self.oncall_max_hours)
            self.work_sat = True
            self.work_sun = True
        else:
            self.hours_worked = random.randrange(self.min_hours, self.max_hours)
            self.work_sat = random.randrange(0,2)
            self.work_sun = random.randrange(0,2)

        self.num_days_worked = 5
        if self.work_sat:
            self.num_days_worked += 1
        if self.work_sun:
            self.num_days_worked += 1

        if self.oncall:
            self.daily_incident_hours = floor((self.hours_worked * self.oncall_incident_percent) / self.num_days_worked)
            self.daily_automation_hours = floor((self.hours_worked * (1 - self.oncall_incident_percent)) / self.num_days_worked)
        else:
            self.daily_incident_hours = floor((self.hours_worked * self.incident_percent) / self.num_days_worked)
            self.daily_automation_hours = floor((self.hours_worked * (1 - self.incident_percent)) / self.num_days_worked)

    def load_config(self):
        with open(config_file, 'r') as fd:
            config = yaml.load(fd)
        self.url = config['url']
        self.email = config['email']
        self.password = config['password']
        self.oncall = config['oncall']
        self.min_hours = config['min_hours']
        self.max_hours = config['max_hours']
        self.oncall_min_hours = config['oncall_min_hours']
        self.oncall_max_hours = config['oncall_max_hours']
        self.incident_project_id = config['incident_project_id']
        self.incident_task_id = config['incident_task_id']
        self.automation_project_id = config['automation_project_id']
        self.automation_task_id = config['automation_task_id']
        self.incident_percent = config['incident_percent']
        self.oncall_incident_percent = config['oncall_incident_percent']

    def load_weeks(self):
        with open('weeks.yaml', 'r') as fd:
            self.weeks = yaml.load(fd)

    def build_weeks(self):
        self.timecard = []
        for week in self.weeks:
            ret = {}
            if self.weeks[week]['oncall']:
                self.oncall = True
            else:
                self.oncall = False
            ret['Sunday'] = {'date': datetime.strftime(self.weeks[week]['start_date'], '%Y-%m-%d')}
            ret['Monday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=1), '%Y-%m-%d')}
            ret['Tuesday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=2), '%Y-%m-%d')}
            ret['Wednesday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=3), '%Y-%m-%d')}
            ret['Thursday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=4), '%Y-%m-%d')}
            ret['Friday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=5), '%Y-%m-%d')}
            ret['Saturday'] = {'date': datetime.strftime(self.weeks[week]['start_date'] + timedelta(days=6), '%Y-%m-%d')}
            week_hours = self.build_week()
            for day in week_hours:
                ret[day]['incident_hours'] = week_hours[day]['incident_hours']
                ret[day]['automation_hours'] = week_hours[day]['automation_hours']
            self.timecard.append(ret)

    def get_hours_worked(self):
        incident_hours_worked = random.randrange((self.daily_incident_hours - 2), (self.daily_incident_hours + 2))
        automation_hours_worked = random.randrange((self.daily_automation_hours - 2), (self.daily_automation_hours + 2))
        return [incident_hours_worked, automation_hours_worked]

    def build_week(self):
        days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
        week = {}
        for day in days:
            if day == 'Sunday':
                if self.work_sun:
                    incident_hours, automation_hours = self.get_hours_worked()
                    week[day] = {'incident_hours': incident_hours, 'automation_hours': automation_hours}
            if day == 'Saturday':
                if self.work_sat:
                    incident_hours, automation_hours = self.get_hours_worked()
                    week[day] = {'incident_hours': incident_hours, 'automation_hours': automation_hours}
            else:
                incident_hours, automation_hours = self.get_hours_worked()
                week[day] = {'incident_hours': incident_hours, 'automation_hours': automation_hours}
        return week

    def post_timecard(self):
        for week in self.timecard:
            for day in week:
                if 'incident_hours' in week[day]:
                    if week[day]['incident_hours'] != 0:
                        data = {'spent_at': week[day]['date'],
                                'hours': week[day]['incident_hours'],
                                'project_id': self.incident_project_id,
                                'task_id': self.incident_task_id}
                        response = self.harvest.add(data)
                        print json.dumps(response(), indent=4)
                if 'automation_hours' in week[day]:
                    if week[day]['automation_hours'] != 0:
                        data = {'spent_at': week[day]['date'],
                                'hours': week[day]['automation_hours'],
                                'project_id': self.automation_project_id,
                                'task_id': self.automation_task_id}
                        response = self.harvest.add(data)
                        print json.dumps(response(), indent=4)
Example #34
0
class HarvestNotifier:

    timer_running = False
    current_project = None
    current_task = None

    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 task_cb(self, widget, event, data=None):

        if self.timer_running:

            self.menu.remove(self.menu.get_children()[0])

        self.harvest.timer_toggle(data['project'], data['task'])

        # button showing what timer we're running
        timer = gtk.MenuItem(data['project']['name'] + " - " +
                             data['task']['name'])
        timer.connect('activate', self.timer_click_cb, self.menu, data)
        self.menu.prepend(timer)
        self.timer_running = True

        self.current_project = data['project']
        self.current_task = data['task']

    def timer_click_cb(self, widget, event, data=None):
        """ Event triggered if a timer is running and someone clicks on the timer """

        if not self.timer_running:
            # we shouldn't get here, but just in case
            return

        self.harvest.timer_toggle(data['project'], data['task'])

        # remove the timer button
        self.menu.remove(widget)
        self.timer_running = False

        self.current_project = None
        self.current_task = None

    def quit_cb(self, widget, data=None):

        if self.timer_running:
            self.harvest.timer_toggle(self.current_project, self.current_task)

        gtk.main_quit()

    def popup_menu_cb(self, widget, button, time, data=None):
        if button == 3:
            if data:
                data.show_all()
                data.popup(None, None, gtk.status_icon_position_menu, 3, time,
                           self.statusIcon)
Example #35
0
class DashBoard(object):

    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)

    def render(self):
        self.create_layout()
        self.document.add(self.layout)
        self.update_data()

    def create_layout(self):

        #button = Button(label="Randomize data", type="success")
        #button.on_click(update_data)
        #top_panel = HBox(children=[button, self.harvest.plot, self.harvest.rate_plot])
        top_panel = HBox(children=[self.harvest.plot, self.harvest.rate_plot])
        domains = VBox(children=[self.domain.sort_relevant_plot, self.domain.sort_crawled_plot, self.domain.sort_frontier_plot], width=200)   
        #middle_panel = HBox(children=[domains, handson.plot])
        middle_panel = HBox(children=[domains])
        layout = VBox(children=[top_panel, middle_panel, self.termite.plot])
        self.layout = layout
        return layout

    def update_data(self):

        self.harvest.source = self.harvest.update_source()
        self.domain.sort_relevant_source, self.domain.sort_crawled_source, self.domain.sort_frontier_source = self.domain.update_source()
        self.termite.data, self.termite.source = self.termite.update_source()
        #self.session.store_objects(ds)
        self.session.store_document(self.document)

        
    def run(self, poll_interval=0.5):
        #link = self.session.object_link(self.document.context)
        #print("Please visit %s to see the plots (press ctrl-C to exit)" % link)

        try:
            while True:
                self.update_data()
                self.session.load_document(self.document)
                time.sleep(poll_interval)
        except KeyboardInterrupt:
            print()
        except ConnectionError:
            print("Connection to bokeh-server was terminated")
Example #36
0
class HarvestNotifier:
    
    timer_running = False
    current_project = None
    current_task = None
    
    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 task_cb(self, widget, event, data = None):
        
        if self.timer_running:

            self.menu.remove(self.menu.get_children()[0])
           
        self.harvest.timer_toggle(data['project'], data['task'])
        
        # button showing what timer we're running
        timer = gtk.MenuItem(data['project']['name'] + " - " + data['task']['name'])
        timer.connect('activate', self.timer_click_cb, self.menu, data)
        self.menu.prepend(timer)
        self.timer_running = True

        self.current_project = data['project']
        self.current_task = data['task']
            
    def timer_click_cb(self, widget, event, data = None):
        """ Event triggered if a timer is running and someone clicks on the timer """
        
        if not self.timer_running:
            # we shouldn't get here, but just in case
            return
        
        self.harvest.timer_toggle(data['project'], data['task'])
        
        # remove the timer button
        self.menu.remove(widget)
        self.timer_running = False

        self.current_project = None
        self.current_task = None
            
        
    def quit_cb(self, widget, data = None):

        if self.timer_running:
            self.harvest.timer_toggle(self.current_project, self.current_task)

        gtk.main_quit()
        
    def popup_menu_cb(self, widget, button, time, data = None):
        if button == 3:
            if data:
                data.show_all()
                data.popup(None, None, gtk.status_icon_position_menu,
                           3, time, self.statusIcon)
Example #37
0
import re
import json
import random
import requests
from harvest import Harvest
harvester = Harvest()

def compareItems(a, b):
    list = []
    list.append(True)
    list.append(False)
    try:
        #print("Comparing " + str(a['type']) + " and " + str(b['type']))
        if str(a['type']) > str(b['type']) or str(a['type']) == str(b['type']) and str(a['name']) > str(b['name']) :
            #print("Returning True")
            return random.choice(list)
        else:
            #print("Returning ?")
            return random.choice(list)
    except:
        # Caters for cases where the name is not present i.e. a fallback function
        #print("Comparing " + str(a['type']) + " and " + str(b['type']))
        if str(a['type']) > str(b['type']):
            #print("Returning ?")
            return True
        else:
            #print("Returning ?")
            return random.choice(list)

def sortJson(_json):
    #print(_json)
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)
Example #39
0
 def from_solution(self, solution):
     for i, harvest in enumerate(solution.harvests):
         self.harvests[i] = Harvest(i)
         self.harvests[i].from_harvest(harvest)
Example #40
0
 def setUp(self):
     self.harvest = Harvest(URL, USER, PWD)
Example #41
0
 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)
Example #42
0
import re
import json
import time
import requests
from harvest import Harvest

harvester = Harvest()

# This is an address from devchain.secondstate.io blockhain
address = "0x3cb71a43c6d9d08b35b48236b759ee201de27679"
# This is a simple parent contract which we are using for demonstrations
abiUrl1 = "https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/parent_abi.txt"
abiData1 = requests.get(abiUrl1).content
abiData1JSON = json.loads(abiData1)

harvester.updateStateOfContractAddress(abiData1JSON, address)
harvester.getDataUsingAddressHash(address)
Example #43
0
import json
import requests
from harvest import Harvest

harvester = Harvest()

#BAT 
abiUrl = "http://api.etherscan.io/api?module=contract&action=getabi&address=0x0d8775f648430679a709e98d2b0cb6250d2887ef&format=raw"
abiData = requests.get(abiUrl).content


officialAbiJSON = json.loads(abiData)
theDeterministicHash = harvester.shaAnAbi(officialAbiJSON)
cleanedAndOrderedAbiText = harvester.cleanAndConvertAbiToText(officialAbiJSON)
erc20Hashes = harvester.createUniqueAbiComparisons(json.loads(cleanedAndOrderedAbiText))
# print("\nThe original ABI is as follows:")
# print(officialAbiJSON)
# print("\nThe cleaned and ordered ABI is as follows:")
# print(cleanedAndOrderedAbiText)
# print("\nThe Sha3 of this ABI is as follows:")
print(theDeterministicHash)
# print("\nThe unique function hashes for this official ERC20 ABI are as follows:")
# print(erc20Hashes)



txReceipt = harvester.web3.eth.getTransactionReceipt("0xcceb1fd34dcc4b18defa4ff29d51a225b20af8ed179db37da72ec5d5a4e8d385")
tx = harvester.web3.eth.getTransaction("0xcceb1fd34dcc4b18defa4ff29d51a225b20af8ed179db37da72ec5d5a4e8d385")
#print("Transaction is as follows:")
#print(tx)
print(officialAbiJSON)
Example #44
0
import json
import requests
from harvest import Harvest
harvester = Harvest()
#abiUrl = "http://api.etherscan.io/api?module=contract&action=getabi&address=0xcb97e65f07da24d46bcdd078ebebd7c6e6e3d750&format=raw"
#abiUrl = "http://api.etherscan.io/api?module=contract&action=getabi&address=0x255aa6df07540cb5d3d297f0d0d4d84cb52bc8e6&format=raw"
# CMT
abiUrl = "http://api.etherscan.io/api?module=contract&action=getabi&address=0xf85feea2fdd81d51177f6b8f35f0e6734ce45f5f&format=raw"

#txHash = "0xd4dc35a1fe48db820b9a5b24f278c732cd624971dd1279dabbd24e347649ba2b"
#txHash = "0xa1d92948229a76e4c386d070355e0adec2736e68ff939ce2c77c65d2e702e3d1"
txHash = "0x4e950082ac6360c6f8152331a30cbad0c7d08525c4c3914d5236d6fc15f684e8"

abiData = requests.get(abiUrl).content
abiJSON = json.loads(abiData)
harvester.processSingleTransaction(abiJSON, txHash)
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)

Example #46
0
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