Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, April 6, 2015

Python Twitter Bot with Tweepy

In an earlier post I laid out a bit how I was working on a twitter bot to automate the promotion of this blog.  I'm a slacker, that has a bad rap for many folks, for me it's the highest calling I can aspire. Get the most accomplished, with the least effort, and disturbance. In the words of Bruce Lee, "Be Like Water, My Friend".  In the dao of piglet, and the te of poo, it's the mystery of being the uncarved block. In the teachings of the Kabbalah or Quabbalah, which was made into such nice easy pictograms in traditional tarot, it's learning to be representative of any, while maintaining your own sense of self.  I have one Boss, and I'm really hoping that Boss never shows up, but I always am sure to recognize There is always a bigger fish. When I crashed the party of social media a few years back, it was never intended to a social outlet. I had already experienced that in years of mmorpg's, irc, bbs, going back to wargames dialers, and phone phreaking. What I was always best at was social hacking, a rather disturbing art when taken to the level of social engineering, or mass media marketing.  After all the drugs, meditation, and study I did over the course of  a lifetime, I finally started to see a pattern, it's not even an unknown pattern, matter of fact it's all over the place, or at least portions of it are.  When I finally awoke to what I had been attempting to understand, about people, and their place in creation, I found that I had missed the relative short window of opportunity to be counted among those who's say carried any weight. In social media I saw an opportunity to leverage the flood of information as a means to get ideas running through my mind. into the hands of those who could make use of them.  I accidently crashed the party of the twitter follow gangs, that handle the bulk of the twitter advertising. It's a fairly ingenious method of leveraging the split platforms of twitter, and sms, in concert to trade influence in the twitter verse. I just saw it as an expedient means of sharing ideas to everyone as quickly as possible, regardless of how they were accepted. I even refused ever offer of easy income, not out a disdain for the finer things the world has to offer, but from an understanding of the myth of an infinite growth paradigm in a zero sum game. I'm speaking of the effects of compounding interest on privatized currency creation. The same effect is seen again and again in almost every market. It's the money itself I have issue with, not currency as an idea. The accounting for who has what, and why, is important. In our current system so many are being left behind, not out of ability, but just by becoming a party to the madness which has a seeming strangle hold on our global civilization. The worship of money, and idol, a representation of something only in potential.  As I said I'm an old school hacker, I once streamlined a system for reporting the percentage of the utilities used in manufacturing in New York state were taxable.  Was a great job while it lasted, at 18 having a work from home job for 10 or 12 an hour is amazing. Taking the time each reports takes to generate from 6 hours to 2 hours, and being told your services are no longer required, not so amazing. Being allowed to help a crop of Police Officers pass a class they had no reason taking, Amazing!. Having your professor tell you there is no place in the world for programming games, again not so amazing. I stopped using computers, and started playing games with them, and then started fixing them.  In the course of my several years of tech service for a local community, what I found was they didn't actually want for me to really solve the issues, they wanted me to manage the problems that cropped up with using outdated, or mixed era systems. Sometimes they almost wanted me to take over the day to day operations of their endeavors. All well and good if it is a mentor situation, when it's a lack of desire to stay current enough to manage your own affairs, well if your not the adult, there aren't many roles left.  After exhausting some of the more entertainment oriented uses for the raspberry pi b+ I turned to what else could this little marvel do. I started seeing vpn's, and pirate drop boxes, wifi extenders to create public clouds all over. All cool concepts, but not much use to me personally, given my current circumstance. Realizing I needed to have a bit of programing brush up, I think the last time I wrote code before this was 88 or so. I hit up code academy, and picked python as it is a seemingly popular high lvl language with many popular api's. I also did some html work, I get it, and it's powerful, it's just puts me to sleep doing it. Even in python as entertaining as it was to create the bot as far as I've taken it, and I am well aware how limited it is in it's current state.  It's basic, but it will tweet for you, pick from search terms to promo others, so your account generates more attention from the community, and will auto follow new folks, and unfollow those that are just attempting to boost numbers. Once I got there essentially I had a automatic twitter promotional bot. Did you know people get paid for doing promotional work on twitter? Even though it makes sense from the marketing game standpoint, that is a slippery area, we are talking about folks that have no moral issue with using psych jobs on children to profit.
So today I'm going post the code for my bot friend. working title was twitternanny, but for easy of use I have taken to naming them after the account they manage. I currently have 2 instances running on my raspberry pi. They may come down at the end of the month, as I have already given notice, my leap of faith I guess, with no place on horizon as of yet. I guess I could always battery power it, and stick in an open wifi cloud in a tree or something, but what would be the point. I ended up using twitter as an object lesson of the insanity of exclusivity.
Enough of my ramble, I get sick of myself sometimes.
here is the code, use it abuse it.



def hourlytweet():
    filename=open(argfile,'r')
    f=filename.readlines()
    filename.close()
    api.update_status(status=f)
    print("hourly tweet posted")


def follow_unfollow():
    followers = api.followers_ids()
    friends = api.friends_ids()

    for z in followers:
        if z not in friends:
            api.create_friendship(z)

    for z in friends:
        if z not in followers:
            api.destroy_friendship(z)
    print("follow, unfollow done")


def search_retweet():
        search_terms= ['python', 'technology', 'raspberry pi', 'ingress', 'news', 'breaking']
        g = random.choice(search_terms)
        g = '#' + g
        results = api.search(q=g, count=1)
        for u in results:
            if u not in alreadytweeted:
                api.retweet(u.id)
                print("retweeted top result for", g)
                alreadytweeted.append(u)



x=1
y=2

while x<y:
    localtime = time.asctime(time.localtime(time.time()))
    hour = int(localtime[11] + localtime[12])
    print('current hour is:',hour)
    if hour>5 and hour<24:
        try:
            hourlytweet()
            time.sleep(1700+random.randint(200,400))
        except:
            print("could not post hourly tweet")
            time.sleep(1700+random.randint(200,400))
        try:
            search_retweet()
            follow_unfollow()
        except:
            print("could not post retweet")
    elif hour == 24 or hour < 6:
        try:
            search_retweet()
            follow_unfollow()
        except:
            pass
    time.sleep(1700+random.randint(200,400))

some of the basic framework came form http://www.dototot.com/how-to-write-a-twitter-bot-with-python-and-tweepy/
So big ups and respect, thanks for the head start, and to those I didn't mention, sorry I use many reference sources when I start a little project.

Thanks
Jack
aka
PanseyBard Digital PiedPiper

Sunday, December 28, 2014

A Pi in the Face

             At it's best this classic gag is surprising, a bit embarrassing, and fun for the whole family. That would be a fairly accurate description for a completely unexpected gift.  A friend who shall remain nameless to protect the guilty handed me a small box, with the odd turn of phrase, "This is not a gag gift".  Being not entirely comfortable with receiving this little mystery box, it was quickly tucked into my pocket, with awkward thanks and banter about, and how I was allowed to open it trailed my foot steps out the door.  A few hours later while comfortably ensconced back at home curiosity brought the little box now on my dresser back to the fore front of my attention.  Not a gag gift huh, well lets find out.  Obeying the instructions to not go easy on the paper, which I was sure to have confirmed by two witnesses, just incase.  Lacking any projected desire, the new Raspberry Pi B+ in it's tiny box took me aback, by it's sheer thoughtfulness.

             For the first time in decades there were visions of sugar plums dancing in my head from a holiday gift.  Lets just say, there is grinch stuff in my room year round, and leave it at that.  Now compelled to express the true gratitude this cool gift engendered,  I did the only sensible thing modern convention allows, sent a text.  Webpages flying by, visions of crazy creative fun, and $70 later the double edged nature of this gift prompted another text.  Something more along the lines of "ok, this thing is so cool, but you just got me to spend $70, on a $35 gift,   I won't be posting any basics on the Pi, there is already so much information available, there is little for me to add,  To start it will just be a basic multifunction system, able to switch between, medi center, retro gaming system, and raspbian(linux distro designed for the pi).  A couple of planned projects with practical application are a dedicated vpn server allowing secured access to the net over any wifi.  An Onion Pi, to allow for less trackable internet access, and finally a private cloud storage server, to keep your data your data, yet still allowing you access to it from anywhere.  These might not seem all that glamorous, but amazingly useful, a low power solution to several common security holes in most peoples digital experience.
          The more fun, less practical ideas will more than likely make an appearance here, perhaps even video's with how too's.  For those wanting some information on this fun, practical device, head on over to http://www.adafruit.com/ or http://www.raspberrypi.org/. If you have ideas for custom builds, or just comments please share.

Jack
aka
PanseyBard

Tuesday, December 17, 2013

Picuntu (linux) Dual Boot with Android

      In my last post I wrote about the fun I was having playing. Well I worked out the glitches I was causing, as well as understanding much better how these devices function.  Now I have a dual booting computer that can fit my pocket.  I really like the idea of being able to just grab and go like that.  Even the idea of being able to eject your sd card, or usb drive, and you've taken your computer away is enticing to me. Shades of hacking on a c64 at pay phone.
     Check out my earlier post for more info. A few troubles I did run into.
1) If your putting it on an sd card be sure it's a 10 or better or it will not be able to power up, and serve the data fast enough, causing problems with booting Picuntu.
2) when using the reboot app do not hit reboot to recovery, it makes it so it will only boot to recovery, and you lose your Android installation. Use boot to bootloader.
3) I got a saned error that that was fixed by changing permissions, this had to be done during the install before you would see the error.
     Other then those it's a pretty easy process, here are a couple of pics, and a video showing both OS's


There is Android, looking all slick. presto chango



A Linux box is born.

and a short clip to show the boot switch

anyone interested in setting one of these up should be sure to check out.
www.freaktab.com
https://www.miniand.com
Picuntu
or contact me, and we can work something out.

be well
Jack
aka
PanseyBard

Sunday, December 15, 2013

Linux on an Android Stick PC

         A little over a year ago I picked up an android mini PC, otherwise known as a TV stick.  These are really fun devices.  Mine is a Dual core 1.6 ghz processor, with 1 gig of ram.  Not a bad little machine to run the droid OS on.  This has been used pretty much as a streaming content device, and at $50 it's not a bad solution for turning any hdmi ready TV into a smart TV.


        Thanks to Sean at gagetreactor for the pic, and a nice overview of this device.  What I find really intriguing about these is the power use.  This works on 3.5 volts at a fixed 6 watts, while here is a nice site that can give you a pretty good idea what your machine at home is using. Most will be over 300 watts, having both 12, and 3.5 volt rails.  Put a full version of a desktop OS on this and wow, your full home set up that you can pop in your pocket, runs on usb, this is amazing.  Like I said it sat being not much more then a entertainment stick, not a bad use mind you, I just like getting more out of my devices. So I finally got into my head to set it up to dual boot between Android, and Linux.  Having played with the Android OS for awhile now, I have come to see that most people can do everything they do with a computer right through it. Even running small businesses, and use only android.  Many still cling to the traditional desktop look and interface, and there are many things on the tech side I would have problems doing through Android.  What I found out was my device had been left in the dust, with the current versions being quad core, with more everything.  Amazing people had been hard at work, reverse engineering, and recompiling code to get a flawless working Linux on the arm processors.  Check out the folks over at Picuntu keep in mind that site is being hosted on a stick, running Picuntu.
       Using several guides, and forums big ups to http://www.freaktab.com/, and https://www.miniand.com/, the forums there are invaluable. Even just flashing the Android OS to the Finless Bob custom rom made the device like new again.  There are a few areas that really gave me fits. I want to make this a dual boot machine, and for some reason my stick will not dual boot as it should with the bootloader from the finless 2.1 release. The 1.6 release loader substituted in nicely, and dual boots nicely. A note on the dual booting, the guides all say to use the reboot app, and boot to recovery to access Linux.  Every time I do this I can no longer boot back to Android.  Sticking to reboot to bootloader solved this problem.  In a few of the guides, and a few places on the forums they tell you to make sure you use a class 10 or higher sd card.  Many will not get why this can be huge, in experimenting I have been using what I have around. This ended up being an 8 gig card I pulled from an Eris I use for mp3.  The problem is this is only a class 4 card, the transfer rates, and even the power up time cause a host of errors all related to data corruption.  While I have been able to set up Picuntu .9c rc2.2 and 3. as well as boot to a Ubuntu desktop, the amount of errors make it not practical.  So I'm going to try using a usb drive, and see how that goes at least till I can get my hands on a different sd card.

Update: switching out the sd card for the usb drive solved the stability issues. Now to get a decent sd card to try it out on.

Jack
aka
PanseyBard

if your feeling generous
btc: 169rA3pQzk1KGh6HjipDYVcNsaKGJFfRQn
ltc:  LUKSpaVnZ6REFs61yG1BnpE5xTzdzje7vE
pts: Pd7xb3Q4idGiGa1iMawVuAYx42WZch1KdG