I'd suggest using cron to schedule the fan's on/off tasks.
Scheduling tasks can be managed by the
shell ~> crontab -e
Add each on/off task. They would look something like:
0 9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off
The actual python script would be straight forward. Import
sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).
import RPi.GPIO as GPIO
# Identify which pin controls transistor
FAN_PIN = 4
# Set pin 4 as output
# Get what action to take
action = sys.argv.pop()
if action == "on" :
print "Turning fan on"
elif action == "off" :
print "Turning fan off"
print "Don't know what to do"