Best Python code snippet using tox_python
project_project.py
Source:project_project.py
1# © 2021 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)2# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).3from odoo import api, fields, models, _4from odoo.exceptions import ValidationError5class Project(models.Model):6 _inherit = "project.project"7 tour_perdiem_config_ids = fields.One2many(8 "project.tour.perdiem.config",9 "project_id",10 "Configuration of Tour Per Diem",11 )12 show_perdiem_config_ids = fields.One2many(13 "project.show.perdiem.config",14 "project_id",15 "Configuration of Show Per Diem",16 )17 show_perdiem_ids = fields.One2many(18 "project.show.perdiem",19 "project_id",20 "Show Per Diem",21 )22 @api.constrains("tour_perdiem_config_ids")23 def _check_duplicate_tour_perdiems(self):24 for project in self:25 types = project.mapped("tour_perdiem_config_ids.type_id")26 if len(types) != len(project.tour_perdiem_config_ids):27 raise ValidationError(_(28 "You may not select multiple applicable per diem "29 "of the same type."30 ))31 @api.constrains("show_perdiem_config_ids")32 def _check_duplicate_show_perdiems(self):33 for project in self:34 types = project.mapped("show_perdiem_config_ids.type_id")35 if len(types) != len(project.show_perdiem_config_ids):36 raise ValidationError(_(37 "You may not select multiple applicable per diem "38 "of the same type."39 ))40 def compute_show_perdiems(self):41 self.show_perdiem_ids = None42 for (43 tour_config,44 show_config,45 partner,46 ) in self._iter_perdiem_compute_parameters():47 vals = self._get_show_perdiem_vals(tour_config, show_config, partner)48 self._create_show_perdiem(vals)49 def _iter_perdiem_compute_parameters(self):50 for partner in self.mapped("show_member_ids.partner_id"):51 for show_config in self.show_perdiem_config_ids:52 tour_config = self._get_tour_perdiem_config(show_config)53 yield tour_config, show_config, partner54 def _get_tour_perdiem_config(self, show_config):55 type_ = show_config.type_id56 tour = self.parent_id57 tour_config = next(58 (p for p in tour.tour_perdiem_config_ids if p.type_id == type_),59 None,60 )61 if tour_config is None:62 raise ValidationError(63 _(64 "The type of perdiem {perdiem_type} is not defined "65 "on the parent tour ({tour})."66 ).format(perdiem_type=type_.display_name, tour=tour.display_name)67 )68 return tour_config69 def _create_show_perdiem(self, vals):70 self.write({"show_perdiem_ids": [(0, 0, vals)]})71 def _get_show_perdiem_vals(self, tour_config, show_config, partner):72 return {73 "partner_id": partner.id,74 "quantity": show_config.quantity,75 "type_id": show_config.type_id.id,76 "unit_amount": tour_config.unit_amount,...
youtube_automate.py
Source:youtube_automate.py
1import feedparser2import requests3from os.path import exists4import json5import subprocess6import ftplib7import sys8import shutil9config_file = __import__('config')10youtube = __import__('youtube')11show_name = sys.argv[1]12show_config = config_file.podcasts[show_name]13print("Checking for new entries")14cache_path = "./cache_" + show_config["general"]["name"] +".json"15file_exists = exists(cache_path)16playlist_url = show_config["general"]["playlist_url"]17Feed = feedparser.parse(playlist_url)18entries = Feed.entries19# For dev purposes only20# with open("feed.xml", 'r') as f:21# Feed = feedparser.parse(str(f.read()))22# entries = Feed.entries23differences = False24links = []25for entry in entries:26 links.append(entry.link)27if file_exists is False:28 print('Cache does not exists')29 json_text = json.dumps(links)30 with open(cache_path, 'w') as f:31 f.write(json_text)32 file_exists = True33if file_exists is True:34 with open(cache_path, 'r') as f:35 json_list = json.loads(str(f.read()))36 json_list = json_list37 if json_list[0] == links[0]:38 print("No changes since last try")39 else:40 entry = links[0]41 print("New links : " + str(entry))42if entry:43 #subprocess.run("python3 botoz3000.py yt-mp3 matinale " + entry, shell=True)44 youtube.video_to_show(show_config, entry)45 path = show_config["item"]["guid"] + "_" + show_config["item"]["ep_id"]46 mp3 = show_config["general"]["name"] + "/" + path + "/" + show_config["item"]["guid"] + ".mp3"47 previous_xml = show_config["general"]["name"] + "/" + path + "/" + show_config["general"]["xml_file_name"] + "-previous.xml"48 new_xml = show_config["general"]["name"] + "/" + path + "/" + show_config["general"]["xml_file_name"] + ".xml"49 server = ftplib.FTP()50 server.connect(show_config["general"]["ftp_url"])51 server.login(show_config["general"]["ftp_login"],show_config["general"]["ftp_password"])52 server.storbinary("STOR " + "/" + show_config["general"]["ftp_folder"] + "/" + show_config["item"]["guid"] + ".mp3", open(mp3, 'rb'))53 server.storlines("STOR " + "/" + show_config["general"]["ftp_folder"] + "/" + show_config["general"]["xml_file_name"] + "-previous.xml", open(previous_xml, 'rb'))54 server.storlines("STOR " + "/" + show_config["general"]["ftp_folder"] + "/" + show_config["general"]["xml_file_name"] + ".xml", open(new_xml, 'rb'))55 server.close()56 json_text = json.dumps(links)57 with open(cache_path, 'w') as f:58 f.write(json_text)59 try:60 shutil.rmtree("./" + show_name)61 except OSError as e:...
metadata_fetching.py
Source:metadata_fetching.py
1# Imports from other dependencies.2from dateutil import parser3# Imports from this library.4from constants import MATCH_ERROR_TEXT5def dummy_fn(show_config, show_metadata, audio_file, matching_episodes):6 return "TK"7def fetch_title(show_config, show_metadata, audio_file, matching_episodes):8 return (9 matching_episodes[0]["Title"]10 if len(matching_episodes) == 111 else MATCH_ERROR_TEXT12 )13def fetch_artist(show_config, show_metadata, audio_file, matching_episodes):14 return show_metadata["Author"]15def fetch_album(show_config, show_metadata, audio_file, matching_episodes):16 return show_metadata["Title"]17def fetch_track_num(show_config, show_metadata, audio_file, matching_episodes):18 if len(matching_episodes) == 1 and "episode_prefix" in show_config:19 show_prefix = show_config["episode_prefix"]20 if matching_episodes[0]["Title"].startswith(show_prefix["start"]):21 episode_candidate = (22 matching_episodes[0]["Title"]23 .lstrip(show_prefix["start"])24 .split(show_prefix["end"])[0]25 .split(" ")[0]26 )27 if episode_candidate.isnumeric():28 highest_numbered_episode = max(29 [30 int(31 _["Title"]32 .lstrip(show_prefix["start"])33 .split(show_prefix["end"])[0]34 .split(" ")[0]35 )36 for _ in show_metadata["PodcastItems"]37 if _["Title"].startswith(show_prefix["start"])38 and _["Title"]39 .lstrip(show_prefix["start"])40 .split(show_prefix["end"])[0]41 .split(" ")[0]42 .isnumeric()43 ]44 )45 return (int(episode_candidate), highest_numbered_episode)46 return (None, None)47def fetch_genre(show_config, show_metadata, audio_file, matching_episodes):48 return "Podcast"49def fetch_date(show_config, show_metadata, audio_file, matching_episodes):50 if len(matching_episodes) != 1:51 return None52 parsed_date = parser.isoparse(matching_episodes[0]["PubDate"])53 return f"{parsed_date.isoformat()[:-6]}Z"54ATTRIBUTE_FETCHERS = dict(55 title=fetch_title,56 artist=fetch_artist,57 album=fetch_album,58 track_num=fetch_track_num,59 genre=fetch_genre,60 date=fetch_date,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!