def _emmet_tokens(tokens): emmet_string = '' for node in tokens: if not node.has_son(): emmet_string += tag(node.name, **node.attrs) else: sons_content = ''.join([_emmet_tokens([son]) for son in node.sons]) emmet_string += tag(node.name, sons_content, **node.attrs) return emmet_string
def generate_database(): for job in jobs(): if tag(job.get("title")): tags = ",".join(tag(job.get("title"))) else: tags = None job_info = (str(job.get("id")), job.get('title'), job.get('body'), job.get('user').get("login"), str_date(job.get('created_at')), tags) insert_job(job_info)
def search(NAME,TIME1,TIME2,TIME3,TIME4): song_name_final = NAME.replace(" ", "+") pre_url = "https://www.youtube.com/results?search_query=" yt_search = pre_url + song_name_final print(yt_search) results = list(YoutubeSearch(str(NAME)).to_dict()) for URLSSS in results: timeyt = URLSSS["duration"] print(URLSSS['title']) try: if timeyt == TIME1: LINKASLI = URLSSS['url_suffix'] break elif timeyt == TIME2: LINKASLI = URLSSS['url_suffix'] break elif timeyt == TIME3: LINKASLI = URLSSS['url_suffix'] break elif timeyt == TIME4: LINKASLI = URLSSS['url_suffix'] break else: pass except: pass global yt_pre yt_pre = str("https://www.youtube.com/" + LINKASLI) print(yt_pre) options = { # PERMANENT options 'format': 'bestaudio/best', 'keepvideo': False, 'outtmpl': f'song//{read(3)}.*', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '320' }], # (OPTIONAL options) 'noplaylist': True } with youtube_dl.YoutubeDL(options) as mp3: mp3.download([yt_pre]) tag.tag()
def author_attribute(req, selectionId, sourceId, authorId, attribute, attributeId): get_object_or_404(Selection, pk=selectionId) get_object_or_404(Source, pk=sourceId) get_object_or_404(Author, pk=authorId) if attribute == 'nations': return tag(req, attributeId) else: raise Http404
def __parse_tag(self, cmd, uid): if not self.__ext_id: return tag(uid) if self.__ext_reqa: if len(uid) in [6, 9, 12]: t = iso1443a(uid[2:], reqa = uid[:2]) elif len(uid) == 13: # ?????? t = iso1443b(uid[0:4], app = uid[4:8], protocol = uid[8:11], cid = uid[11]) else: raise ACG_BadResponse(cmd, bin2asc(uid)) else: if len(uid) in [5, 8, 11]: t = iso1443a(uid[1:], cascade = uid[0]) elif len(uid) == 12: t = iso1443b(uid[0:4], app = uid[4:8], protocol = uid[8:11], cid = uid[11]) else: raise ACG_BadResponse(cmd, bin2asc(uid)) return t
def source_attribute(req, selectionId, sourceId, attribute, attributeId): get_object_or_404(Selection, pk=selectionId) get_object_or_404(Source, pk=sourceId) if attribute in source_tag_types: return tag(req, attributeId) elif attribute == 'author': return author(req, attributeId) else: raise Http404
def test_tag(): # A single positional argument produces an empty tag with that name assert tag('br') == '<br />' # Any number of arguments after the first are captured by *content as a tuple assert tag('p', 'hello') == '<p>hello</p>' assert tag('p', 'hello', 'world') == '<p>hello</p>\n<p>world</p>' # Keyword arguments not eplicitly named (e.g., id) in the tag signature are captured by **attrs # as a dict assert tag('p', 'hello', id=33) == '<p id="33">hello</p>' # The cls parameter can only be passed as a keyword argument, it will never capture unnamed # positional arguments assert tag('p', 'hello', 'world', cls='sidebar') == \ '<p class="sidebar">hello</p>\n<p class="sidebar">world</p>' # Even the first positional argument can be passed as a keyword argument assert tag(content='testing', name="img") == '<img content="testing" />' my_tag = { 'name': 'img', 'title': 'Sunset Boulevard', 'src': 'sunset.jpg', 'cls': 'framed' } # Prefixing the my_tag dict with ** passes all its items as separate arguments, which are then # bound to the named parameters. which the remaining caught by **attrs assert tag( **my_tag ) == '<img class="framed" src="sunset.jpg" title="Sunset Boulevard" />'
def selection_attribute(req, selectionId, attribute, attributeId): get_object_or_404(Selection, pk=selectionId) if attribute in selection_tags: return tag(req, attributeId) elif attribute == 'source': return source(req, attributeId) elif attribute == 'quotations': return quotation(req, attributeId) else: raise Http404
def get_tags(self) : tree = self.open_xml("tags.xml") root = tree.getroot() tags = [] for item in root : tag_item = tag(item.find("name").text) tag_item.set_id(item.find("id").text) tag_item.set_is_active(item.find("is_active").text) tags.append(tag_item) return tags
def release(force='no'): """ Tag, push tag to Github, & upload new version to PyPI. """ tag.tag(force=force, push='yes') upload()
def release(force='no'): """ Tag/push, build, upload new version and build/upload documentation. """ tag.tag(force=force, push='yes') upload()
def exportar(nome, lista): print(tag.tag(nome, *lista))
from xmlFile import xmlFile from tag import tag """ The only work performed by the parser is to create a string, which would be json formated thanks to the tag class and the two jsonFormat functions. There is a unique call to the formatNameAndAttributes method which is recursive and a unique call to the getTags method which is also recursive. We need to create an empty tag "tag" to call the getTags method. It also use the xmlFile class. The parser does not handle : - <unique/> tags - multiple text - text that does appear after embedded tags """ with open('small.xml', 'r') as file: data = file.read().replace('\n', '') fileToConvert = xmlFile(data) fileToConvert.getHeaderAndBody() result = "{\n" tag = tag(0, "", "", [], "", 0) body = tag.getTags(fileToConvert.body, 1) result += body.formatNameAndAttributes() result += '}' result = result[:-3] + result[-2:] #uncomment the following line to print the ouput #print(result) with open('small.json', 'w') as outfile: outfile.write(result)
""" Extended function calls examples """ from geometry import hypervolume print(hypervolume(2,4)) # => 8 print(hypervolume(2,4,6)) # => 48 print(hypervolume(2,4,6,8)) # => 384 from tag import tag print(tag('img', src='monet.jpg', alt='Sunrise by Claude Monet', border=1)) # Extended call syntax def print_args(arg1, arg2, *args): print(arg1) print(arg2) print(args) t = (1,2,3) print_args(*t) # 1 # 2 # (3,) def color(red, green, blue, **kwargs):
import tag import generate __author__ = "imdreamrunner" __email__ = "*****@*****.**" logging.basicConfig(level=logging.DEBUG) log = logging.getLogger(__name__) if __name__ == "__main__": print("Welcome to Reader") args = sys.argv if len(args) != 2: print("Usage: python reader.py <fetch|generate>") exit(1) command = args[1] if command == "fetch": log.debug("Command: fetch") fetch.fetch_all() summarize.summarize() translate.translate() tag.tag() elif command == "generate": log.debug("Command: generate") generate.generate() else: print("Unknown command: " + command) log.info("Program exits.")
def addTag(self, tagObject): text = tagObject.findChild().text tagCat = tagObject.attrs["class"][1] tagId = tagObject.attrs["id"] newTag = tag(text, tagCat, tagId, self.postId) self.tags.append(newTag)
global info audioFile = glob.glob("./*{}.mp3".format(info["id"]))[0] newName = audioFile.replace("-{}".format(info["id"]), "") os.rename(audioFile, newName) # Saves the album cover def saveAlbumArt(): global info thumbnails = sorted(info["thumbnails"], key=lambda x: x["width"], reverse=True) # Download & save the file urllib.request.urlretrieve(thumbnails[0]["url"], "thumbnail.webp") im = Image.open("thumbnail.webp").convert("RGB") im.save("thumbnail.jpeg", "jpeg") os.remove("thumbnail.webp") # Cut the cover out of it im = Image.open("thumbnail.jpeg") w, h = im.size im.crop(((w - h) // 2, 0, (w + h) // 2, h)).save("thumbnail.jpeg") download(sys.argv[1]) saveAlbumArt() tag.tag(info)