本文整理汇总了Python中fancy.ANSI.C类的典型用法代码示例。如果您正苦于以下问题:Python C类的具体用法?Python C怎么用?Python C使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了C类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkreport
def checkreport(fn, o):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('FIXD'))
r = checkon(fn, o)
# non-verbose mode by default
if verbose or r != 0:
report(statuses[r], fn)
return r
示例2: checkreport
def checkreport(fn, o):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('WARN'))
r, msg = checkon(fn, o)
# non-verbose mode by default
if verbose or r != 0:
print('[ {} ] {}: {}'.format(statuses[r], fn, msg))
return r
示例3: checkon
def checkon(fn, o):
if not os.path.exists(fn) or os.path.isdir(fn):
fn = fn + '.json'
if not os.path.exists(fn):
# if it still does not exist, let us create a minimal one
f = open(fn, 'w')
f.write('{{\n\t"title": "{name}",\n\t"type": "proceedings",\n\t"year": {year}\n}}'.format(\
name=fn.split('/')[-1][:-5].replace('-', ' '),
year=findYear(fn.split('/')[-1])\
))
f.close()
print('[ {} ] {}'.format(C.yellow('MADE'), fn))
return 2
f = open(fn, 'r')
lines = f.readlines()[1:-1]
f.close()
for line in lines:
if line.find('"year"') > -1 and findYear(line) > 3000:
os.remove(fn)
print('[ {} ] {}'.format(C.red('KILL'), fn))
return 1
flines = sorted([strictstrip(s) for s in lines])
plines = sorted([strictstrip(s) for s in o.getJSON().split('\n')[1:-1]])
if flines != plines:
f1 = [line for line in flines if line not in plines]
f2 = [line for line in plines if line not in flines]
print('∆:', f1, '\nvs', f2)
if flines == plines:
return 0
else:
return 1
示例4: checkreport
def checkreport(m, o):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('FIXD'))
r = checkon(m, o)
# non-verbose mode by default
if verbose or r != 0:
print('[ {} ] {}'.format(statuses[r], o.filename))
return r
示例5: report
def report(fn, r):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('UNEX'))
special = ('', '- no crossref found!', '- illegal crossref')
# non-verbose mode by default
if verbose or r != 0:
print('[ {} ] {} {}'.format(statuses[r], fn, special[r]))
return r
示例6: checkreport
def checkreport(fn, o, br):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('FIXD'))
if br:
r = checkbrand(fn, br)
else:
r = checkon(fn, o)
# non-verbose mode by default
if verbose or r != 0:
print('[ {} ] {}'.format(statuses[r], fn))
return r
示例7: checkreport
def checkreport(fn, o):
statuses = (C.blue('PASS'), C.red('FAIL'), C.yellow('FIXD'))
if isinstance(o, int):
r = o
else:
r = checkon(fn, o)
# non-verbose mode by default
if verbose or r != 0:
print('[ {} ] {}'.format(statuses[r], fn))
return r
示例8: checkon
def checkon(m, o):
# if no common model found, we failed
if not m:
return 1
if 'type' in m.keys() and m['type'] in ('inproceedings', 'article'):
m['type'] = 'proceedings'
if 'type' in m.keys() and m['type'] == 'incollection':
m['type'] = 'book'
if 'crossref' in m.keys():
del m['crossref']
if 'booktitle' in m.keys():
m['title'] = m['booktitle']
del m['booktitle']
if 'booktitleshort' in m.keys():
# TODO: ???
del m['booktitleshort']
r = 0
n = {}
for k in m.keys():
if o.get(k) == m[k]:
if verbose:
print(C.blue('Confirmed: '), k, 'as', m[k])
else:
if verbose:
print(C.red('Conflicted: '), k, 'as', m[k], 'vs', o.get(k))
v = heurichoose(k, m[k], o.json[k]) if k in o.json.keys() else m[k]
if verbose:
print(C.yellow('Settled for:'), v)
n[k] = v
r = 2
if r == 0:
return r
if r == 2 and not n:
# nothing to fix?!
return 0
if not os.path.exists(o.filename):
return 0
if os.path.isdir(o.filename):
fn = o.filename + '.json'
else:
fn = o.filename
if os.path.exists(fn):
f = open(fn, 'r')
lines = f.read()
f.close()
if lines != o.getJSON():
# strange, should be equal (run all normalisers first!)
return 1
for k in n.keys():
o.json[k] = n[k]
f = open(fn, 'w')
f.write(o.getJSON())
f.close()
return 2
示例9: __init__
def __init__(self, d, hdir, name2file, parent):
super(Venue, self).__init__(d, hdir)
self.years = []
self.brands = []
self.n2f = name2file
if os.path.exists(d+'.json'):
# new style
# print(C.blue(d), 'is new style')
self.json = parseJSON(d+'.json')
else:
# legacy style
print(C.red(d), 'is legacy style')
self.json = []
for f in glob.glob(d+'/*.json'):
if not self.json:
self.json = parseJSON(f)
else:
self.brands.append(Brand(f, self.homedir, name2file, self))
for f in glob.glob(d+'/*'):
if f.endswith('.json'):
# already processed
continue
elif os.path.isdir(f):
y = Year(f, self.homedir, name2file, self)
self.years.append(y)
for b in self.brands:
for c in y.confs:
b.offer(y.year, c)
else:
print('File out of place:', f)
self.back = parent
示例10: processSortedRel
def processSortedRel(r):
# [ {"x" : Y } ] where Y can be a string or a sorted rel
global pcx
acc = []
for el in r:
ename = list(el.keys())[0]
evals = el[ename]
if os.path.isfile(outputdir + '/stuff/' + ename.lower() + '.png'):
img = '<img src="../stuff/{1}.png" alt="{0}" width="30px"/> '.format(ename, ename.lower())
else:
img = ''
if isinstance(evals, str):
plst = sorted(matchfromsleigh(sleigh, evals), key=sortbypages)
pcx += len(plst)
ptxt = '<dl class="toc">'+'\n'.join([p.getItem() for p in plst])+'</dl>'
elif isinstance(evals, list) and isinstance(evals[0], str):
plst = sorted(matchfromsleigh(sleigh, evals), key=sortbypages)
pcx += len(plst)
ptxt = '<dl class="toc">'+'\n'.join([p.getItem() for p in plst])+'</dl>'
elif isinstance(evals, list) and isinstance(evals[0], dict):
ptxt = processSortedRel(evals)
else:
print(C.red('ERROR:'), 'unrecornised bundle structure', evals)
acc.append('<dl><dt>{}{}</dt><dd>{}</dl>'.format(img, ename, ptxt))
return '\n'.join(acc)
示例11: parseJSON
def parseJSON(fn):
# print('Parsing',fn,'...')
try:
j = json.load(open(fn, 'r'))
j['FILE'] = fn
return j
except ValueError:
print(C.red('JSON parse error'), 'on', fn)
return {}
示例12: guessYear
def guessYear(p):
cys = [int(w) for w in p.split('-') if len(w) == 4 and w.isdigit()]
if len(cys) == 1:
return cys[0]
else:
j = sleigh.seekByKey(p)
if 'year' in j.json.keys():
return j.get('year')
elif 'year' in dir(j):
return j.year
else:
print('[ {} ] {}'.format(C.red('YEAR'), p))
return 0
示例13: sortbypages
def sortbypages(z):
if 'pages' not in z.json.keys():
print(C.red('No pages at all in '+z.getKey()))
return 0
p1, _ = z.getPagesTuple()
y = z.get('year')
if isinstance(y, str):
# non-correcting robustness
return 0
# a trick to have several volumes within one conference
v = z.get('volume')
if isinstance(v, int) or v.isdigit():
y += int(v)
return y + p1 / 10000. if p1 else y
示例14: dblpify
def dblpify(s):
# http://dblp.uni-trier.de/pers/hd/e/Elbaum:Sebastian_G=
if s in dis.keys():
return dis[s]
if s.find(' ') < 0:
print('[', C.red('NAME'), ']', 'Unconventional full name:', s)
cx[1] += 1
return dblpLatin(s)+':'
ws = s.split(' ')
i = -1
if ws[i] in ('Jr', 'Jr.'):
i -= 1
sur = dblpLatin(' '.join(ws[i:]))
rest = dblpLatin(' '.join(ws[:i])).replace(' ', '_')
for c in ".'-":
rest = rest.replace(c, '=')
return sur+':'+rest
示例15: checkon
def checkon(fn, o):
if not os.path.exists(fn) or os.path.isdir(fn):
fn = fn + '.json'
if 'title' not in o.json.keys():
if verbose:
print('No title in', o.getKey())
return 1 # no title
# check for a different language - to avoid stemming altogether
if o.tags and ('german' in o.tags or 'french' in o.tags or 'portuguese' in o.tags):
if 'stemmed' in o.json.keys():
# if stemmed before marked foreign, remove this info
del o.json['stemmed']
F = open(fn, 'w')
F.write(o.getJSON())
F.close()
return 2
else:
return 0
changed = False
### champion variant: snowballstemmer - runs in ~13.5s for 96027 titles
stemmer = snowballstemmer.stemmer('english').stemWords
### disregarded variant: snowballstemmer porter - considered outdated
# stemmer = snowballstemmer.stemmer('porter').stemWords
### disregarded variant: stemming - too slow, runs in ~33s for 96027 titles
# stemmer = lambda xs: [stemming.porter2.stem(x) for x in xs]
### disregarded variant: nltk - worse on verbs ending with -ze
# stemmer3 = lambda xs: [SnowballStemmer("english").stem(x) for x in xs]
### end variants
stemmed = stemmer(string2words(o.get('title')))
if '' in stemmed:
print('“{}” is a title of {} and it has an empty word'.format(o.get('title'), C.red(o.getKey())))
print(string2words(o.get('title')))
print(stemmer(string2words(o.get('title'))))
ALLSTEMS.update(stemmed)
if o.get('stemmed') != stemmed:
o.json['stemmed'] = stemmed
changed = True
if changed:
F = open(fn, 'w')
F.write(o.getJSON())
F.close()
return 2
else:
return 0