Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a script (Python)
#1
Hello dear forum,

we have a web radio and the following rules apply:
- There are two folders from which the script (playlist.py) pulls the songs. Once from 10-0 and once from 0-10. Now we want the following structure:

0 - 6> NightRotation
6 - 12> Midday rotation
12 - 18> DayRotation
18 - 24> evening rotation

And that the jingles are played every 5 songs.

Unfortunately, we are completely noobs in terms of Python, and because of our studies, our PRG is no longer able to participate. Therefore I would be happy if you solve this problem for us :-)


#!/usr/bin/env python



heavyRotationPercentage = 1.0 / 2.0



import os

import random

import pickle

import datetime



directory = os.path.dirname(os.path.abspath(__file__))

heavyRotationDir = os.path.join(directory, "HeavyRotation")

normalRotationDir = os.path.join(directory, "NormalRotation")

oldRotationDir = os.path.join(directory, "OldRotation")

jinglesDir = os.path.join(directory, "Jingles")

statusFile = os.path.join(directory, "status.txt")

currentHour = datetime.datetime.now().hour



status = [('','')]*8



if os.path.isfile(statusFile):

    with open(statusFile, "rb") as f:

        status = pickle.load(f)

lastFiles = [i[0] for i in status]



fileListFilter = lambda fileList: [fileName for fileName in fileList if

                                   fileName not in lastFiles and fileName[-4:] == ".mp3"]



choosenFileDir = False

choosenFileList = False





if status[-1][1]!=jinglesDir:

    #Letzte Track war kein Jingle

    choosenFileDir = jinglesDir

    choosenFileList = fileListFilter(os.listdir(jinglesDir))





if currentHour >= 10 and choosenFileDir == False:

    #Von 10:00 bis 24:00 aus der normalen / Heavy Rotation waehlen

    filesInHeavyRotation = fileListFilter(os.listdir(heavyRotationDir))

    filesInNormalRotation = fileListFilter(os.listdir(normalRotationDir))

    if random.random() <= heavyRotationPercentage and len(filesInHeavyRotation) > 0:

        choosenFileDir = heavyRotationDir

        choosenFileList = filesInHeavyRotation

    elif len(filesInNormalRotation) > 0:

        choosenFileDir = normalRotationDir

        choosenFileList = filesInNormalRotation



if choosenFileDir == False:

    # Von 00:00 bis 10:00 (oder wenn nichts anderes gefunden wurde) aus der alten Rotation waehlen

    choosenFileDir = oldRotationDir

    choosenFileList = fileListFilter(os.listdir(oldRotationDir))





choosenFile = random.choice(choosenFileList)



with open(statusFile, "wb") as f:

    status.append((choosenFile, choosenFileDir))

    pickle.dump(status[1:],f)



print os.path.join(choosenFileDir, choosenFile)
Reply
#2
homework?
Reply
#3
we have a web radio and do not have the knowledge to change the script. So I wanted to ask if anyone has any idea about it. Unfortunately we don't have time to learn the language
Reply
#4
we have a jobs section where you can post, but please state compensation amount.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,007 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,788 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,248 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,583 May-11-2019, 08:12 PM
Last Post: keames
  How to run python script which has dependent python script in another folder? PrateekG 1 3,105 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,286 May-16-2018, 02:08 AM
Last Post: lravikumarvsp
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,788 Jul-07-2017, 08:59 AM
Last Post: snippsat
  Cant pass corect variables to python script in bash script neradp 3 6,130 Nov-05-2016, 01:26 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020