Posted by, Chris Kankiewicz on February 14th, 2009
This is an update to the previous post found here: http://www.web-geek.net/posts/2008/10/20/calculate-the-first-friday-of-next-month-with-php/
With this update I have drastically reduced and simpified the code to produce the same results. I did some rigorous testing of my own to make sure this script will calculate the correct date, but that doesn’t mean it’s bullet-proof. If you find a bug, please email me so I can fix it.
first-friday.php
<?php // first-friday.php v0.1.3 by, Chris Kankiewicz <http://www.web-geek.net>
// Calculate next Friday
for ($x = date('d'); $x <= (date('d') + 6); $x++) {
$timeStamp = mktime(0,0,0,date('m'),$x,date('Y'));
if (date('w',$timeStamp) == 5) {
$nextFriday = mktime(0,0,0,date('m'),$x,date('Y'));
}
}
// Check if next Friday is the first friday of the month.
if (date('d', $nextFriday) <= 7) {
$firstFriday = $nextFriday;
} else {
// Calculate first Friday of next month
for ($x = 1; $x <= 7; $x++) {
$timeStamp = mktime(0,0,0,date('m')+1,$x,date('Y'));
if (date('w',$timeStamp) == 5) {
$firstFriday = mktime(0,0,0,date('m')+1,$x,date('Y'));
}
}
}
// Echo next first Friday
echo date("F j, Y", $firstFriday);
?>
Posted by, Chris Kankiewicz on October 20th, 2008
UPDATE: This script has been updated, see: http://www.web-geek.net/posts/2009/02/14/first-friday-script-updated-and-simplified/
While developing phx2600.org, I ran into a slight dilemma. The PHX2600 meetings occur once a month on the first Friday of every month, and we wanted to display that on the site. However, it was becoming a tedious chore to change the date once a month manually. So, being the automation addict I am, I thought, why not write a script. So one night I hammered out the following script that will calculate the first Friday of next month:
Read the rest of this entry »
Posted by, Chris Kankiewicz on September 30th, 2008
This is my first python script I ever wrote. This script connects to whatismyip.com, fetches the external IP address of the network you are on, puts it into a text file and uploads it via FTP to any server you want.
At home I have Cox, therefore I have a dynamic IP. Even though this IP only changes about once every month, I got sick of needing to connect to my home computer via VNC and not being able because my IP had changed. Therefore I created the following script and set up a scheduled task on my home computer to run this script every hour.
After running this script, you can then use PHP (or any similar language) to include this file into any page you desire.
#! /usr/bin/env python
import httplib
import sys
import os
import ftplib
file="ip.txt"
conn = httplib.HTTPConnection("www.whatismyip.com")
conn.request("GET","/automation/n09230945.asp")
response = conn.getresponse()
data = response.read()
filename = str(os.path.abspath(os.path.dirname(sys.argv[0])) + "\\"+file) #Create file
FILE = open(filename,"w") #Open file ready for writing
FILE.writelines(data) #Write 'data' to file
FILE.close() #Close file
#Replace [server], [user], and [pass] with your information.
s = ftplib.FTP('[server]','[user]','[pass]') #Connect
f = open(file,'rb') #File to send
s.storbinary('STOR '+file, f) #Send the file
f.close() #Close file and FTP
s.quit() #Quit FTP
sys.exit(0)
Download IP-Uploader (< 1KB)
Shouts to Automated Penguin and Nak!