Created
January 19, 2017 22:51
-
-
Save Hellowlol/26bc66e3c32e1a8942ad725919e5502b to your computer and use it in GitHub Desktop.
plexapi assert bastard py2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def assertme(m, monsterassert=True): | |
with open('asserted.txt', 'w') as f: | |
todo = [] | |
def inner(m=None, override_name=''): | |
keys = sorted([k for k in m.__dict__.keys() if not k.startswith('_')]) | |
tags = ['genres', 'roles', 'writers', 'directors', 'writers'] | |
l_type_to_inspect = ['videoStreams', 'part', 'subtitleStreams', | |
'media', 'audioStreams', 'parts', 'streams', 'video'] | |
for k in keys: | |
try: | |
v = m.__dict__.get(k) | |
ass_start = override_name or 'ep' | |
if k.startswith('_'): | |
continue | |
# check new classes | |
print repr(v), type(v) | |
#if inspect.isclass(v) or isinstance(v, type(v)) and not isinstance(v, datetime.datetime): | |
# print 'is class' | |
# kek_name = '%s' % (k[:3]) | |
# #f.write('# Assign %s %s.%s\n' % (ass_start, k)) | |
# #f.write('%s = %s.%s[%s]\n' % (kek_name, ass_start, k, i)) | |
# func = partial(inner, m=v, override_name=kek_name) | |
# todo.append(func) | |
#continue | |
if isinstance(v, (str, unicode)): | |
v = "'%s'" % v.encode('utf-8') | |
elif isinstance(v, datetime.datetime): | |
v = "'%s'" % str(v.date()) | |
k = "str(%s.%s.date())" % (ass_start, k) | |
elif isinstance(v, list) and k in tags: | |
v = [i.tag for i in v] | |
k = '[i.tag for i in %s.%s]' % (ass_start, k) | |
elif isinstance(v, list) and k in l_type_to_inspect: | |
if monsterassert: | |
for i, nn in enumerate(v): | |
kek_name = '%s%s' % (k[:3], i) | |
f.write('# Assign %s %s.%s\n' % (i, ass_start, k)) | |
f.write('%s = %s.%s[%s]\n' % (kek_name, ass_start, k, i)) | |
func = partial(inner, m=v[i], override_name=kek_name) | |
todo.append(func) | |
#raise Breakloop | |
continue | |
if k == 'server': | |
v = "'%s'" % v.baseurl | |
k = 'server.baseurl' | |
if k == 'summary': | |
v = 'u"%s"' % v | |
check = '==' | |
if isinstance(v, _NA): | |
try: | |
k = "str(%s.%s)" % (ass_start, k) | |
v = "'__NA__'" | |
except Exception as e: | |
print e | |
if v is None or v is True or v is False: | |
check = 'is' | |
if isinstance(v, (str, unicode)) and v.startswith('<'): | |
continue | |
if ass_start in k: | |
f.write('assert %s %s %s\n' % (k, check, v)) | |
else: | |
f.write('assert %s.%s %s %s\n' % (ass_start, k, check, v)) | |
except Breakloop: | |
continue | |
inner(m) | |
print len(todo) | |
for z in todo: | |
z() | |
print('done') | |
assertme(m, monsterassert=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment