Jump to content

bschultz

Members
  • Posts

    486
  • Joined

  • Last visited

Everything posted by bschultz

  1. I work at a radio station in the US. We are required to air some commercial content from our news provider. Our commercial scheduling people are currently putting these commercials in by hand (they read the providers webpage for the schedule that tells them which commercials are to be played...and when they are to be aired). I'd begun writing some code to read through their html page to download the commercials and rename them so that they can show up each day on the on-air log...and they would air when they are supposed to. Now, the provider is providing an xml file...which should ease how I'm pulling the info...but I'm running into some problems. Here's the xml: <BroadcastLogs> <DayData> <Date>2015-05-11</Date> <Rotation> <Time> 6a - 7p</Time> <SpotData> <SpotTitle>Biore</SpotTitle> <SpotISCI>QBIO-0065-000</SpotISCI> <Length>30</Length> <Type>Primary</Type> <SpotType/><Script></Script> </SpotData> <SpotData> <SpotTitle>Motel 6</SpotTitle> <SpotISCI>YOTL-5022-000</SpotISCI> <Length>30</Length> <Type>Linked</Type> <SpotType/><Script></Script> </SpotData> </Rotation> <Rotation> <Time> 6a - 7p</Time> <SpotData> <SpotTitle>Biore</SpotTitle> <SpotISCI>QBIO-0065-000</SpotISCI> <Length>30</Length> <Type>Primary</Type> <SpotType/><Script></Script> </SpotData> <SpotData> <SpotTitle>Motel 6</SpotTitle> <SpotISCI>YOTL-5022-000</SpotISCI> <Length>30</Length> <Type>Linked</Type> <SpotType/><Script></Script> </SpotData> </Rotation> <Rotation> <Time> 6a - 7p</Time> <SpotData> <SpotTitle>Sprint/Boost Promotional Offer</SpotTitle> <SpotISCI>BQRAA-4051</SpotISCI> <Length>60</Length> <Type>Primary</Type> <SpotType/><Script></Script> </SpotData> </Rotation> </DayData> </BroadcastLogs> You will notice that there's only one <DayData><Date>xxxx-xx-xx</Date> for the day...which shouldn't be to tough to solve. The part I'm having a problem with is if the commercial is 30 seconds...there are TWO ads...for every ONE <rotation> tag. Here you will find TWO 30 seconds ads <Rotation> <Time> 6a - 7p</Time> <SpotData> <SpotTitle>Biore</SpotTitle> <SpotISCI>QBIO-0065-000</SpotISCI> <Length>30</Length> <Type>Primary</Type> <SpotType/><Script></Script> </SpotData> <SpotData> <SpotTitle>Motel 6</SpotTitle> <SpotISCI>YOTL-5022-000</SpotISCI> <Length>30</Length> <Type>Linked</Type> <SpotType/><Script></Script> </SpotData> </Rotation> If the commercial is a 60 second commercial...there's only ONE <rotation> tag... <Rotation> <Time> 6a - 7p</Time> <SpotData> <SpotTitle>Sprint/Boost Promotional Offer</SpotTitle> <SpotISCI>BQRAA-4051</SpotISCI> <Length>60</Length> <Type>Primary</Type> <SpotType/><Script></Script> </SpotData> </Rotation> I've tried some code from the php.net site...but could seem to get the foreach's right for the difference in tags used if it's a 30 second or a 60 seconds ad. Now, I'm trying this code: <?php function RecurseXML($xml,$parent="") { $child_count = 0; foreach($xml as $key=>$value) { $child_count++; if(RecurseXML($value,$parent.".".$key) == 0) // no childern, aka "leaf node" { //////////the code on the following line was taken from a google search...and worked by displaying $parent, $key and $value // print($parent . "." . (string)$key . " = " . (string)$value . "<br />\n"); ////// I added the next section to the code, to set variables if ($parent . "." . (string)$key === '.DayData.Date') { $date = (string)$value; } if ($parent . "." . (string)$key === '.DayData.Rotation.Time') { $time = (string)$value; } if ($parent . "." . (string)$key === '.DayData.Rotation.SpotData.SpotTitle') { $title = (string)$value; } if ($parent . "." . (string)$key === '.DayData.Rotation.SpotData.SpotISCI') { $link = (string)$value; } if ($parent . "." . (string)$key === '.DayData.Rotation.SpotData.Length') { $length = (string)$value; } } echo "Date - " . $date . "<br />Time - " . $time . "<br />Title - " . $title . "<br />Link - " . $link . "<br />Length - " . $length . "<br />-------------------<br />"; } return $child_count; } $string = file_get_contents('full url goes here'); $xml = new SimpleXMLElement($string); RecurseXML($xml); ?> The code above isn't working since the loop is off...the first line returned is the date...the next four are blank. The next chunk has the date empty, the time is listed...and the rest in that chunk are blank...and so on. What I need is the values for: DayData->Date DayData->Rotation->Time DayData->Rotation->SpotData->SpotTitle DayData->Rotation->SpotData->SpotISCI DayData->Rotation->SpotData->Length Am I even on the right path here? I've never dealt with xml...much less parsing it! Thanks!
  2. I work at a radio station. Each week, we have to download (using SCP or wget) a bunch of mp3's to air during the weekend. The problem I'm having is that the remote directory that these files are located in changes the name from one week to another. For instance, this week one directory is named 'Live In Concert ROCK (Sunday) 02.22.15 version3'. Next week, it might be 'Live In Concert ROCK (Sunday) 02.29.15 version2' What I need is a matching pattern of 'Live in Concert' and the 'date'...and there will be other stuff in between those two patterns. To complicate this...it's on a remote machine. What are my options? Thanks.
  3. Typecast worked for the int values...but all the other fields had whitespace too. I ran trim on the foreach for the array...and it didn't work. I ran trim on the insert of the mysql table for each field...and it worked. Still don't know where the whitespace came from, but I got rid of it. Thanks!
  4. That's what I have for them. The WYSIWYG box shows the copied data...not the raw html. If they don't know how to read the html, how are they supposed to know what to label the elements for my code?
  5. My clients have ZERO html knowledge...they copy and paste...there's no way for them to know what the elements are from one schol to the next.
  6. No two schools put things in the same order or with the same div or column names. The method I am using lets the end user select the order of the roster they are loading at that time based on which column is which. IE: column 1 is number, column 2 is name, column 3 is a picture of the payer (which we don't use and ignore), column 4 is their height. Next week, it might be column 1 name, column 2 number...etc. One week the school may only provide a Word document in table format... Like I said, there are no set formats of what is being copied and pasted in. As long as the info being gathered is in table form (which is the case 95+ percent of the time), my system can adapt. If you can show me how DOM or html_simple_dom would work better...I'd love to hear it.
  7. copy and paste the roster from the schools website into a wysiwyg text box on my site. That entry runs through HTML Purifier to clean up formatting other than the table tr and td tags...then put into an array. The array is then split by < td > to find each inidividual roster entry (number, name, height, weight etc.). I was using strip_tags to get rid of everything other than table tr and td...but a new school had embedded p tags inside the td tag...which killed the import. HTML Purifier is cleaning up the entered code...but I don't know where the extra whitespace is coming from. Still haven't had a chance to play with typecast, but will soon.
  8. I tried trim, ltrim and rtirm last night...none seemed to work. I'll try typecast today...thanks!
  9. Ever heard of HTML Purifier adding whitespace at the end of tags? I'm trying to import sports jersey numbers into a DB...as int. Whitespace is killing the import.
  10. That explains it...I put the allowed tags in brackets...thanks!
  11. HTML Purifier didn't remove the inner tags either...
  12. I need to strip some html tags out of an uploaded string of code. I need to keep the <td> tags...but some code that is being uploaded include <p> tags INSIDE the <td> tag. How would I go about stripping ALL other tags inside these allowed tags: <td> <tr><table>
  13. Why is it you always find the right Google phrase AFTER you post the questions? ${'pos_' . $i}
  14. I'm have a hard time figuring out variable variables. if (${$pos_$i} == '1234') So, the $i is in a loop... The full variables are $pos_1, $pos_2, $pos_3 etc. How can get this to work? The code above throws a Parse error: syntax error, unexpected T_VARIABLE in... error. Thanks!
  15. The following code ran as true on Friday at 11:45pm...and $showname did not equal anything...anyone know why? if ((($dow != 'Friday' || $dow != 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife') This should only run on Sunday, MOnday, Tuesday, Wednesday and Thursday night at 11:45pm...or when run from command line passing the variable Showname the value of livingthecountrylife. The date and time variables are set like this: $year = date('Y'); // 4 digit $month = date('m'); // with leading zeros $date = date('d'); // with leading zeros $dow = date('l'); // Sunday Monday Tuesday...etc $hour = date('H'); // 24 hour with leading zeros $minute = date('i'); // with leading zero $now = date('Y-m-d'); Thanks!
  16. I changed plans and went with GET variables to set the start date and the end date of the time frame wanted....more flexible anyway. Thanks!
  17. I tried... $sql = 'SELECT * FROM table WHERE WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY)) AND WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL -7 DAY))'; And I got back results from March...
  18. I have a column (DATE) for bithdays...how can I select in MYSQL which birthdays were last week...and the upcoming week? I found this...but it's only for the upcoming week...not last week too... $sql = 'SELECT * FROM table WHERE WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY))'; How can I adjust this to include last week too? Thanks.
  19. Thanks... by the way, here's the current code snipit...with column names... mysql_select_db($db,$dbc); $sql = "SELECT * FROM downloads"; $rs = mysql_query($sql,$dbc); while($row = mysql_fetch_array($rs)) { $row = $row['row']; $name = $row['name']; $min = $row['min']; $hour = $row['hour']; $dom = $row['dom']; $mon = $row['mon']; $dow = $row['dow']; $type = $row['type']; $filetype = $row['filetype']; $url = $row['url']; $username = $row['username']; $password = $row['password']; $local_path = $row['local_path']; $remote_path = $row['remote_path']; $a1037 = $row['a1037']; $a983 = $row['a983']; $a921 = $row['a921']; $a1360 = $row['a1360']; $a1300 = $row['a1300']; // rest of code here }
  20. Monkeypaw...that's correct, 1 cron job running 1 script. I've found a problem in both of our logic, though. if(date("i") == $minute || $minute == '*') { $doirun = TRUE; } if(date("H") == $hour || $hour == '*') { $doirun = TRUE; } If the download should occur at 0:10 of each hour...hour will be * in the database...meaning that it would execute every minute (date("H") == $hour || $hour == '*') when the cron job runs...since hour = * How can I account for all of the different if statements that will be needed to act in a similar fashion as cron?
  21. I'd currently work for a radio station. On a daily and weekly basis we need to download certain files (mp3) for playback later. I currently have about 50 cron jobs scheduled to download the files at a given time or day. I'd like to consolidate these files and jobs. I'd like to have one cron job set to run every minute to execute a php script that will do the download if the time is a database is correct. How can I write the logic of the if statements in the php script to follow similar logic as cron (0 10 * * *) like 10am every day? I have the datatype in mysql set as varchar so that I can include the * wildcard. Here's what I've come up with. Is there a "better" way to accomplish this? $run = 0; if ($min == $current_minute || $min == '*') { $run = 1; } if ($hour == $current_hour || $hour == '*') { $run = 1; } if ($dom == $current_dom || $dom == '*') { $run = 1; } if ($mon == $current_mon || $mon == '*') { $run = 1; } if ($dow == $current_dow || $dow == '*') { $run = 1; } if ($run = 0) { exit; ) elseif ($run == 1) { execute rest of script here }
  22. The database is structured as name...not first name and last name. Since that's the way the rosters are formatted, that's the way the db was formatted. I did a little research on full text search and it looks promissing. I've only tested for the player I refferenced above, D. Kroeplin...and it worked. I'm guessing it's slow though. Is it? And is there any way to keep the db as is...and still use LIKE like you suggested?
  23. Alright, so levenshtein didn't work at all... Kroeplin, D. (as taken from the stats page of the team---which is Dustin Kroeplin) came back as Dustin Dowd using levenshtein. Back to square one I guess!
  24. This is for a football stats system. The user enters the teams roster (which goes into the database. Then they enter the player stats. All of this information is listed on the schools website. Problem is, so schools put stats online in first last order...some put last, first...some put last, first initial (2 initials if there's a John Smith and a Jim Smith (Jo. and Ji.). I just need to match the full name that's in the database. If there's a mulitple possible match, I suppose I could add a check for the user to choose which player it is. It's VERY rare that a team has more than one player with a same last name. I won't have time to work on this project til the weekend...I'll probably be back then with further questions.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.