Advertisement
Guest User

Untitled

a guest
May 25th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.60 KB | None | 0 0
  1. import requests, re, random, os, mimetypes,json
  2. from lxml.html import fromstring
  3.  
  4.  
  5. def retro(sfondo, font, testo1, testo2, testo3):
  6.     # sfondo: 1,2,3,4,5
  7.     # font: 1,2,3,4
  8.     # testo max 15 caratteri
  9.     #crea un immagine 'retro' a partire da un testo
  10.     headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:43.0) Gecko/20100101 Firefox/43.0'}
  11.     data = {'current-category': 'all_effects', 'bcg': sfondo, 'txt': font, 'text1': testo1, 'text2': testo2, 'text3': testo3}
  12.     r = requests.post('https://photofunia.com/categories/all_effects/retro-wave?server=3', data=data, headers=headers)
  13.     links = fromstring(r.text).xpath('//a[normalize-space() = "Large"]/@href')
  14.     link = links[0][:-9] if len(links) > 0 else None
  15.     return link
  16.  
  17.  
  18. def owo(testo):
  19.     #ritorna desto owoificato
  20.     facce = ['(・`ω´・)', ';;w;;', 'owo', 'UwU', '>w<', '^w^']
  21.     testo = re.sub('[rl]', 'w', testo)
  22.     testo = re.sub('[RL]', 'W', testo)
  23.     testo = re.sub('n([aeiou]+)', r'ny\1', testo)
  24.     testo = re.sub('N([aeiou]+)', r'Ny\1', testo)
  25.     testo = re.sub('N([AEIOU]+)', r'Ny\1', testo)
  26.     testo = re.sub('ove', 'uv', testo)
  27.     testo = re.sub('!+', ' ' + random.choice(facce) + ' ', testo)
  28.     return testo
  29.  
  30.  
  31. def aesthetics(testo):
  32.     #ritorna testo con effetto vaporwave
  33.     lista_asiatici = """リサフランク現代のコンピュ竹内 まりや若者が履く流行のスニーカー真夜中のドアホットドッグマスターストライカーソニ
  34. ーブギ新しい日の誕生ライフ - ヒスイ蒸気波 無線゠ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネ
  35. ノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・ーヽヾヿぁあぃいぅうぇえぉおかがきぎくぐけげこご
  36. さざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ゙゚゛゜
  37. ゝゞゟ亜哀挨愛曖悪握圧扱宛嵐安案暗以衣位囲医依委威為畏胃尉異移萎偉椅彙意違維慰遺緯域育壱逸茨芋引印因咽姻員院淫陰飲隠韻右宇羽雨唄鬱畝浦運雲永
  38. 泳英映栄営詠影鋭衛易疫益液駅悦越謁閲円延沿炎怨宴媛援園煙猿遠鉛塩演縁艶汚王凹央応往押旺欧殴桜翁奥横岡屋億憶臆虞乙俺卸音恩温穏下化火加可仮何花
  39. 佳価果河苛科"""
  40.     n = max(3, len(testo.split()))
  41.     return "".join(x if not ord(x) in range(33, 127) else chr(ord(x) + 65248) for x in testo) + "   " + \
  42.            "".join(random.choice(lista_asiatici) for y in range(n))
  43.  
  44.  
  45. def flip_testo(testo):
  46.     #ribalta testo
  47.     testo = testo.lower()
  48.     alfabeto = {'a': 'ɐ', 'b': 'q', 'c': 'ɔ', 'd': 'p', 'e': 'ǝ', 'f': 'ɟ', 'g': 'b', 'h': 'ɥ', 'i': 'ı', 'j': 'ظ',
  49.                 'k': 'ʞ', 'l': 'ן', 'm': 'ɯ', 'n': 'u', 'o': 'o', 'p': 'd', 'q': 'b', 'r': 'ɹ', 's': 's', 't': 'ʇ',
  50.                 'u': 'n', 'v': 'ʌ', 'w': 'ʍ', 'x': 'x', 'y': 'ʎ', 'z': 'z', '[': ']', ']': '[', '(': ')', ')': '(',
  51.                 '{': '}', '}': '{', '?': '¿', '¿': '?', '!': '¡', '\'': ',', ',': '\'', '.': '˙', '_': '‾', ';': '؛',
  52.                 '9': '6', '6': '9'}
  53.     return "".join(alfabeto.get(x, x) for x in testo[::-1])
  54.  
  55.  
  56. def rip(testo1, nome='R.I.P.', testo2='Hopes and Dreams'):
  57.     #crea tomba personalizzata partendo da un testo
  58.     return 'http://www.tombstonebuilder.com/generate.php?top1={0}&top3={1}&top4={2}'.format(nome, testo1, testo2)
  59.  
  60.  
  61. def minecraft(nome, testo):
  62.     #crea achievement di minecraft personalizzato partendo da un testo
  63.     return 'https://mcgen.herokuapp.com/a.php?i=1&h=Achievement-{0}&t={1}'.format(nome, testo)
  64.  
  65.  
  66. def tono(testo):
  67.     #analizza le emozioni presenti in un testo
  68.     data = {'text': testo, 'language': 'en'}
  69.     headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:46.0) Gecko/20100101 Firefox/46.0.2 Waterfox/46.0.2'}
  70.     json = requests.post('https://tone-analyzer-demo.ng.bluemix.net/api/tone', data=data, headers=headers).json()
  71.     toni = json['document_tone']['tones']
  72.     if len(toni) == 0:
  73.         return None
  74.     return [tono['tone_name'] for tono in toni if tono['score'] >= 0.75]
  75.  
  76.  
  77. def identifica(img_path):
  78.     #identifica un'immagine
  79.     s = requests.Session()
  80.     mime = mimetypes.guess_type(img_path)[0]
  81.     name = os.path.basename(img_path)
  82.     files = {'file': (name, open(img_path, 'rb'), mime)}
  83.     risp = s.post('https://www.captionbot.ai/api/upload', files=files)
  84.     url_immagine = risp.text[1:-1]
  85.     data = {'Content': url_immagine, 'Type': 'CaptionRequest'}
  86.     headers = {'Content-Type': 'application/json; charset=utf-8'}
  87.     risp = s.post('https://captionbot.azurewebsites.net/api/messages', data=json.dumps(data), headers=headers)
  88.     if not risp.ok:
  89.         return None
  90.     messaggio = risp.text[1:-1].replace('\\"', '"').replace('\\n', '\n')
  91.     return messaggio
  92.  
  93.  
  94. def smart(testo):
  95.     #scarica file e apri in locale
  96.     json = requests.get('https://honk.moe/tools/thesaurus.json').json()
  97.     stop = {'ourselves', 'hers', 'between', 'yourself', 'but', 'again', 'there', 'about', 'once', 'during', 'out',
  98.             'having', 'with', 'they', 'own', 'an', 'be', 'some', 'for', 'do', 'its', 'yours', 'such', 'into', 'of',
  99.             'most', 'itself', 'other', 'off', 'is', 's', 'am', 'or', 'who', 'as', 'from', 'him', 'each', 'the',
  100.             'themselves', 'until', 'below', 'are', 'we', 'these', 'your', 'his', 'through', 'don', 'nor', 'me', 'were',
  101.             'her', 'more', 'himself', 'this', 'down', 'should', 'our', 'their', 'while', 'above', 'both', 'up', 'to',
  102.             'ours', 'had', 'she', 'all', 'no', 'when', 'at', 'any', 'before', 'them', 'same', 'and', 'been', 'have',
  103.             'in', 'will', 'on', 'does', 'yourselves', 'then', 'that', 'because', 'what', 'over', 'why', 'so', 'can',
  104.             'did', 'not', 'now', 'under', 'he', 'you', 'herself', 'has', 'just', 'where', 'too', 'only', 'myself',
  105.             'which', 'those', 'i', 'after', 'few', 'whom', 't', 'being', 'if', 'theirs', 'my', 'against', 'a', 'by',
  106.             'doing', 'it', 'how', 'further', 'was', 'here', 'than', 'get', 'go'}
  107.     testo = testo.lower()
  108.     parole = testo.split(' ')
  109.     messaggio = ''
  110.     for parola in parole:
  111.         if parola not in stop:
  112.             parola = json.get(parola) if json.get(parola) is not None else parola
  113.         messaggio += parola + " "
  114.     return ''.join(frase.capitalize() for frase in re.split('([.!?] )', messaggio))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement