-
Notifications
You must be signed in to change notification settings - Fork 436
Sample group filtering #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
samples/group_filtering.py
Outdated
group1 = TSC.GroupItem(group_name) | ||
group1 = server.groups.create(group1) | ||
print(group1) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should catch a specific set of exceptions rather than all of them
samples/group_filtering.py
Outdated
|
||
group_name = 'SALES+ROMANIA' | ||
options = TSC.RequestOptions() | ||
options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment to explain what you are going here
Just pushed a commit addressing past feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits but I think they're worth it
samples/filter_sort_groups.py
Outdated
parser.add_argument('-p', default=None) | ||
args = parser.parse_args() | ||
|
||
password = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary, the if/then should catch all cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, you mean it is not necessary to set passsword = ''
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, password gets set in all cases because args.p is either None
, or it isn't.
So the initial password = '' is redundant. It doesn't hurt anything either :P
samples/filter_sort_groups.py
Outdated
try: | ||
group1 = TSC.GroupItem(group_name) | ||
group1 = server.groups.create(group1) | ||
print(group1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to print something more meaningful than the repr of a group?
eg "Group created: "
samples/filter_sort_groups.py
Outdated
try: | ||
group2 = TSC.GroupItem(group_name) | ||
group2 = server.groups.create(group2) | ||
print(group2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
samples/filter_sort_groups.py
Outdated
TSC.RequestOptions.Operator.Equals, | ||
filter_group_name)) | ||
|
||
filtered_group_paged = server.groups.get(req_options=options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pager again (Samples aren't always just run against new servers, often it's existing servers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore -- this is filtered
samples/filter_sort_groups.py
Outdated
filtered_group_paged = server.groups.get(req_options=options) | ||
|
||
# Return type is a tuple with the first entry as a list of matching groups | ||
print(filtered_group_paged[0][0].name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tuple unpacking or comment please
samples/filter_sort_groups.py
Outdated
|
||
filtered_groups, _ = server.groups.get(req_options=options) | ||
# Result can either be a matching group or none | ||
group_name = filtered_groups.pop().name if len(filtered_groups) != 0 else 'No project named \'' + str(filter_group_name) + '\' found ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if filtered_groups:
group_name = filtered_groups.pop()
else:
error = "No project named '{}' found".format(filter_group_name)
print(error)
Reads cleaner to me, then we aren't overloading the group_name as either a name OR an error string.
Empty lists in python are false-y, so you can just truth test it (if filtered_groups
). Or there's a bug, because len(None)
will through an error.
I may run over to clarify some things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final nit.
🚀
import tableauserverclient as TSC | ||
|
||
|
||
def create_example_group(group_name='Example Group', server=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
isn't actually a safe default, this should just be a standard required parameter.
* Sample group filtering script * Added comments and specific error catching * Renamed the file to follow the naming convention * commented on return type, example group creation, cleaned up code * Better way to call and catch return from rest api * Proper printing instructions
* Sample group filtering script * Added comments and specific error catching * Renamed the file to follow the naming convention * commented on return type, example group creation, cleaned up code * Better way to call and catch return from rest api * Proper printing instructions
Create python-package.yml
Added a script for group filtering.