diff --git a/bwdata.py b/bwdata.py index 5c75c4a..3c76e10 100644 --- a/bwdata.py +++ b/bwdata.py @@ -1,5 +1,5 @@ """ -bwrdata contains the BWData class. +bwdata contains the BWData class. """ import datetime import filters @@ -760,15 +760,29 @@ def _get_date_ranges(self, query_id=None): return self.project.get(endpoint="queries/"+str(query_id)+"/"+"date-range") def _fill_params(self, name, startDate, data): + try: + int(name) + numerical = True + except ValueError: + numerical = False + if not name: raise KeyError("Must specify query or group name", data) - elif name not in self.ids: - raise KeyError("Could not find " + self.resource_type + " " + name, self.ids) + elif numerical: + if int(name) not in self.ids.values(): + raise KeyError("Could not find " + self.resource_type + " " + name, self.ids) + elif not numerical: + if name not in self.ids: + raise KeyError("Could not find " + self.resource_type + " " + name, self.ids) if not startDate: raise KeyError("Must provide start date", data) filled = {} - filled[self.resource_id_name] = self.ids[name] + if numerical: + filled[self.resource_id_name] = name + else: + filled[self.resource_id_name] = name + filled["startDate"] = startDate filled["endDate"] = data["endDate"] if "endDate" in data else ( datetime.date.today() + datetime.timedelta(days=1)).isoformat() diff --git a/bwproject.py b/bwproject.py index 871d47a..bdbf782 100644 --- a/bwproject.py +++ b/bwproject.py @@ -244,9 +244,22 @@ def get_project(self, project): projects = self.get_projects() project_found = False + try: + int(project) + numerical = True + except: + numerical = False + for p in projects: - if p["name"] == project: - self.project_name = project + found = False + if numerical: + if p["id"] == int(project): + found = True + else: + if p["name"] == project: + found = True + if found: + self.project_name = p["name"] self.project_id = p["id"] self.project_address = "projects/" + str(self.project_id) + "/" project_found = True diff --git a/setup.py b/setup.py index be59e98..18a2eae 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='bwapi', - version='1.0.8', + version='1.0.9', description='A software development kit for the Brandwatch API',