But I think you would probably be fine with using something like this --- which I found after a quick search engine and choosing the top hit. The code there is pretty straightforward and copy-able.
Aside: I tried to decide if I thought this was on-topic here. I would say it's borderline on-topic, but probably on the off-topic side of the border. If you have further programming questions, the appropriate place to ask them is on one of the programming sites on the network, such as StackOverflow.