I'm following a tutorial on YouTube that shows how to get recent tweets from a user. However I run into a
TypeError: TwitterUserScraper.__init__() takes 2 positional arguments but 3 were given.
Below is the code.
import snscrape.modules.twitter as twitterScraper
scraper = twitterScraper.TwitterUserScraper("elonmusk", False)
for i, tweet in enumerate(scraper.get_items()):
if i > 2:
break
print(f"{i} content: {tweet.content}")
I'm not really sure how I can fix this since I have copied the code straight from the video. Thanks for the help.
Related
I am trying to concat a list of audio inputs using ffmpeg-python. The exception in the question title is being thrown when attempting to execute the following code:
music_streams = []
for path in random.choices(os.listdir(music_dir), k=song_count):
path = os.path.join(music_dir, path)
music = ffmpeg.input(path)
music_streams.append(music)
music_joined = ffmpeg.concat(*music_streams)
out = ffmpeg.output(music_joined, 'out.mp3')
out.run()
Need advice on how to do this correctly. Thank you.
Ended up solving this on my own. Adding v=0 and a=1 arguments to the concat call and it is working as expected. If someone can explain what was going on here, I will +1 you for sure. Fairly new to ffmpeg. I am assuming the exception is because it is also trying to concat video streams (and their subtitles?), but since these are audio files, there are none. ffmpeg-python needs to know this explicitly. Could be wrong on my understanding, though.
music_joined = ffmpeg.concat(*music_streams, v=0, a=1)
I just got my first Raspberry Pi product last week. I got a Raspberry Pi Zero W, and a PiCamera. I created a program (to be ran each day by crontab) that will take a photo, store the photo locally, transfer a copy of the photo to a local server, make a CSV log of the photo, and make an easily readable text daily report. I've gotten almost everything working correctly, but I have one particular issue I can't seem to figure out.
I'm using the Python PiCamera library to capture the photos everyday, and I wanted to set some static GPS data to each photo's EXIF metadata. (The GPS data needs to be static because the Pi is suction cupped to a window and wont be moving for at least a year) The issue I need help with is that I do not know how EXACTLY I need to format my GPS data for PiCamera's exif_tag property. Here are some of the formats I've tried and have not given me appropriate results:
Attempt #1 - Float
camera.exif_tags["GPS.GPSLatitude"] = 41.1027
camera.exif_tags["GPS.GPSLongitude"] = -85.1362
I get this error:
Traceback (most recent call last):
File "main.py", line 13, in <module>
camera.capture(local_path)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1418, in capture
encoder.start(output)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1125, in start
self._add_exif_tag(tag, value)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1097, in _add_exif_tag
ct.sizeof(mmal.MMAL_PARAMETER_EXIF_T) + len(tag) + len(value) + 1)
TypeError: object of type 'float' has no len()
Attempt #2 - String
camera.exif_tags["GPS.GPSLatitude"] = "41.1027"
camera.exif_tags["GPS.GPSLongitude"] = "-85.1362"
No error is produced when running this code, however the output data from the exif after the image is captured is still inaccurate:
Latitude |0.040
Longitude |3162715.1775
Follow Up Attempts - Other Strings
# Style 1
camera.exif_tags["GPS.GPSLatitude"] = "(41) (6) (10.711)"
camera.exif_tags["GPS.GPSLongitude"] = "(85) (8) (8.968)"
# This produces
Latitude |1.00
Longitude |1.00
# Style 2
camera.exif_tags["GPS.GPSLatitude"] = "41 6 10.711"
camera.exif_tags["GPS.GPSLongitude"] = "85 8 8.968"
# This produces
Latitude |6.8
Longitude |10.6
# Style 3
camera.exif_tags["GPS.GPSLatitude"] = "41, 6, 10.711"
camera.exif_tags["GPS.GPSLongitude"] = "85, 8, 8.968"
#This produces
Latitude |6.8, 0.014, 1.000
Longitude |10.6, 0.008, 2.141837875
So, in short, can anyone help me by providing me with the means to format my strings? I am at a complete loss. The documentation for PiCamera only lists the different tags but does not explain how to format each of them.
Alright, so after several more test cases, a couple hours of research, and finally posting an issue on the PiCamera GitHub repo I finally figured it out. There is no direct documentation on this particular part of the PiCamera library as stated in my question. But someone on the repo was able to point me to the RaspiStill repo on adding GPS exif data, which is written in C. I've never completely learned C and my C++ skills are a bit rusty, but it gave me an idea. The end result came out to this:
camera.exif_tags["GPS.GPSLatitude"] = "41/1,6/1,9577/1000"
camera.exif_tags["GPS.GPSLongitude"] = "85/1,8/1,10223/1000"
When looking over the RaspiStill repo it got me thinking of how you would use the commands in the terminal to set exif data, so I looked up how to set the coordinates via RaspiStill and found this documentation which gave an example.
RaspiStill Documentation
Some examples of how to represent the data in the form of degrees, minutes, and seconds:
52 = 52 / 1 (52 units)
40.44 = 4044 / 100 (4044 hundredths)
52.97790 = 52977900 / 1000000 (52977900 millionths)
0 = 0/1
This is the source of where I found how to do the above "calculations":
Geotag - Exif Data
Hopefully this can help someone else too.
For context: I am using the Py app on iPhone which runs and displays code.
What baffles me is when my code stated the following:
import numpy as np
b = np.array([1,2,3])
two_level = np.array([[1,2,3,4],[5,6,7,8]])
print(two_level)
print(two_level[0,3])
print(two_level.ndim)
print(two_level.shape)
print(two_level.size)
a = np.ones((3,2))
print(a)
Everything ran appropriately and as normal. Then, I added these lines:
c = np.zeroes((2,3))
print(c)
Everything about two_level printed fine, then instead of printing c OR a it then gave me several paragraphs of green text along the lines of :
File "string", line 11, in module
File "/var/containers/Bundle/Application/B96C5A02-913D-4CBE-BE73-9B0912C447FA/Python.app/otherscripts/numpy/core/numeric.py", line 1869, in array_str
...and so on. I realized "zeroes" was actually "zeros" and corrected this and ran it again. But it came with the same error message (except the part about not finding "zeroes"). Then I erased the part of my code in regards to c, running only the code that had worked before without error messages. The same thing happened as with c included and two_level printed fine, but a did not print and resulted in the same long error message.
Being that the same code that had previously worked now does not work, did I break something? I am confused as to what is going on...
Update: the app I'm using to run the code just can't run very large files without crashing.
I've been trying to figure out this problem the entire day. I'm trying to add a image at the bottom of every video in a directory.
Here is the error that i get after writing just 4 videos out of 100
del self.reader
AttributeError: reader
Exception ignored in: <bound method VideoFileClip.__del__ of <moviepy.video.io.VideoFileClip.VideoFileClip object at 0x03D787B0>>
Here is how im trying to write the video
video = CompositeVideoClip([clip1, clip2.set_duration(clip1.duration)])
video = CompositeVideoClip("mixclip"+random.randint(999,999999)"+.mp4")
del video
del clip1
del clip2
Edit: Posted a slightly wrong code which i made while i was testing and got a instant a -1. Changed it. But i still cannot find solution to this problem.
Edit2: Tested alot and figured it out. Fixed it by declaring clip2 duration before mixing it. Rewrote entire code didn't check what other changes i made but its working as intended now.
Update to the latest version at the GitHub repo or wait until the next moviepy update is pushed to PyPI, where this is fixed. (See these commits: one, two)
However, unless you tell us what the line
video = CompositeVideoClip("mixclip"+random.randint(999,999999)"+.mp4")
means, you may be coming across an underlying problem with your usage.
Just a side note: the above line has a couple of errors; change it to this:
video = CompositeVideoClip("mixclip" + str(random.randint(999, 999999)) + ".mp4")
I am using the Twython module and am trying to upload a picture as my status on my Twitter account.
from twython import Twython
TWITTER_APP_KEY = '#myappkey'
TWITTER_APP_KEY_SECRET = '#myappkeysecret'
TWITTER_ACCESS_TOKEN = '#myaccesstoken'
TWITTER_ACCESS_TOKEN_SECRET = '#myaccesstokensecret'
t = Twython(TWITTER_APP_KEY, TWITTER_APP_KEY_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
photo = open('twitterpics/picture.jpg', 'rb')
t.update_status_with_media(status='hello!', media=photo)
The code above gives the error below:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "twythonlearning.py", line 21, in <module>
t.update_status_with_media(status='hello!', media=photo)
TypeError: update_status_with_media() takes at least 2 arguments (1 given)
Other functions such as t.update_status(status='test') or t.get_home_timeline() work perfectly fine. I have searched online for similar problems and can't seem to find the problem with my code. I have tried capitalising the arguments 'status' and 'media' and I've also checked the size of the media file which is less than 3mb (only 75k).
Any help would be appreciated.
Thanks
I tried your code and it works for me.
Not sure what it could be though , as all i did was copy and paste into a new file and add my keys etc in, open a local file and it worked.
Not much help sorry but maybe try just creating a new file and starting again and adding the code in there. I had a similar issue when I was messing about with Twython and I for the life of me couldn't work out what was wrong. So just reverted to a previous working version and went from there.
Only suggestion is that maybe the image is malformed and therefore it is giving you an error. Try a different image.
You should really be using this method of tweeting with an image, upload the image and then add the image id to the update_status , maybe that will work for you.
photo = open('twitterpics/picture.jpg', 'rb')
ids = twitter.upload_media(media=photo)
twitter.update_status(status='Checkout this cool image!', media_ids=ids['media_id'])